Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 什么´;Qt中的这个模板有什么问题?QFile已删除构造函数?_C++_Qt_Templates_Methods_Qfile - Fatal编程技术网

C++ 什么´;Qt中的这个模板有什么问题?QFile已删除构造函数?

C++ 什么´;Qt中的这个模板有什么问题?QFile已删除构造函数?,c++,qt,templates,methods,qfile,C++,Qt,Templates,Methods,Qfile,这是我的模板函数。我得到了错误信息“调用'QFile'的已删除构造函数”。 我怎样才能解决这个问题?或者你能告诉我建议,我怎样才能以最好的方式编写这个函数作为模板 template <class T> // T shall be the name of a class void example(QVector<T> &vec, const QString &fp, std::function<void(QFile)> func) //f

这是我的模板函数。我得到了错误信息“调用'QFile'的已删除构造函数”。 我怎样才能解决这个问题?或者你能告诉我建议,我怎样才能以最好的方式编写这个函数作为模板

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();
}
template//T应为类的名称
void示例(QVector&vec,const QString&fp,std::function func)//func是类中的方法
{
qfilef(fp);
如果(!f.open(QIODevice::WriteOnly | QIODevice::Append))
{

qDebug()无法复制
QFile
,因为复制构造函数已被删除。 将
example
的签名改为使用
std::function 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;
}