[英]What´s wrong with this template in Qt? QFile deleted constructor?
So, this is my template function.所以,这是我的模板函数。 And I get the error massage "call to deleted constructor of 'QFile' ".我收到错误消息“调用已删除的 'QFile' 构造函数”。 How can I fix this?我怎样才能解决这个问题? Or can you tell me recommendation, how can I write this function as template in best way?或者你能告诉我推荐,我怎样才能以最好的方式编写这个函数作为模板?
template <class T> // T shall be the name of a class
void example(QVector<T> &vec, const QString &fp, std::function<void(QFile)> func) //func is a method from a class
{
QFile f(fp);
if(!f.open(QIODevice::WriteOnly | QIODevice::Append) )
{
qDebug() << "File error" << f.error();
}
else
{
QThread::currentThread();
for(T &tw : vec)
{
//tw.func(f);
func(f).tw; **//call to deleted constructor of 'QFile'**
}
}
f.close();
}
func can be this for example: func 可以是这样的,例如:
void writeTeamData(QFile&);
void teamType::writeTeams(QFile &f)
{
QTextStream out(&f);
out.setCodec("UTF-16LE");
out << teamId << "\t" << offsideTrap << "\t" << withoutBall << "\t" << formationId << "\t"
<< attack << "\t" << teamMentality << "\t" << attackTactic1 << "\t"
<< attackTactic2 << "\t" << defenseTactic1 << "\t" << defenseTactic2 << "\t" << captain << "\t"
<< penaltyTakerId << "\t" << kickTakerId << "\t" << leftCornerkickTakerId << "\t" << rightCornerkickTakerId << "\t"
<< numTransfersIn << endl;
}
You cannot copy a QFile
as the copy constructor has been deleted.您不能复制QFile
因为复制构造函数已被删除。 Change the signature of example
to take a std::function<void(QFile&)> func
instead.更改example
的签名以采用std::function<void(QFile&)> func
代替。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.