c++ - QVector.push_back 错误

标签 c++ qt

错误

QVector<LibraryRecord> Library;
Library.push_back(LibraryRecord(DateOfIssue, ReturnDate, FIO,tTekct,FName,TText));

错误信息:

 no matching function for call to ‘LibraryRecord::LibraryRecord()’

为什么?构造函数存在

//constructor
LibraryRecord::LibraryRecord(QString pDateOfIssue,
                             QString pReturnDate,
                             QString FIO,
                             QString tTekct,
                             QString fName,
                                 QString TTextt)
{..}

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

最佳答案

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

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

关于c++ - QVector.push_back 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7537491/

相关文章:

c++ - 为什么在调整大小后我仍然可以访问 vector 数据?

c++ - Boost Overload 奇怪的行为.. `int (int ), int (std::string )` 与 `int (int ), int (std::string ), std::string (std::string)` 有何不同?

qt - 蓝牙:如何从MAP读取 “Message Notification Service”(MNS)中的消息? QT

c++ - move std::unique_ptr的构造函数/分配:内存重新分配?

c++ - 如果使用优化 (-O2, -O3),为什么这段代码的行为会有所不同?

c++ - 理解 `std::stack`的容器模板参数

c++ - 在 Qml 场景下使用 OpenGL 渲染时出现奇怪的错误

c++ - Qml Grid、Column 和 RowLayout 不适用于 LayoutMirroring

qt - QTreeView中选择慢,为什么?

c++ - Qt中如何检查文件是否被数据库驱动占用