QVector.push_back错误

Бор*_*ска 4 c++ qt

错误

QVector<LibraryRecord> Library;
Library.push_back(LibraryRecord(DateOfIssue, ReturnDate, FIO,tTekct,FName,TText));
Run Code Online (Sandbox Code Playgroud)

错误信息:

 no matching function for call to ‘LibraryRecord::LibraryRecord()’
Run Code Online (Sandbox Code Playgroud)

为什么?构造函数存在

//constructor
LibraryRecord::LibraryRecord(QString pDateOfIssue,
                             QString pReturnDate,
                             QString FIO,
                             QString tTekct,
                             QString fName,
                                 QString TTextt)
{..}
Run Code Online (Sandbox Code Playgroud)

你能告诉我怎么解决这个问题吗?提前致谢!

Jam*_*lis 11

与C++标准库容器(例如std::vector)不同,Qt容器要求值类型是默认可构造的.

也就是说,您的类型LibraryRecord还必须具有默认构造函数(您显示的构造函数,它需要参数,不是默认构造函数).

  • 但是,`QList`没有这个要求,所以我最终在某些地方使用它,我更喜欢使用`QStack`或`QVector`但需要支持非默认构造类型. (2认同)