C++ - Qt Strange QList::at() error
C++ - Qt Strange QList::at() error
void MainWindow::onWishlistEditButtonClicked()
{
QInputDialog *inputDialog = new QInputDialog();
inputDialog->setOptions( QInputDialog::NoButtons );
static QString defaultText = "Default Wishlist";
//No Error here, prints 0 as expected
qDebug() << wishLists.size();
bool isOk = false;
QString text = inputDialog->getText( NULL, "Create a Wishlist", "Wishlist Name: ", QLineEdit::Normal, defaultText, &isOk );
if( isOk && !text.isEmpty() ) {
if( text.length() >= 100 ) {
defaultText = text; //on next pop up this will be the text
//let user know that the maximum number can only be 100
QMessageBox::critical( this, "Error", "The maximum number of characters is 100.", QMessageBox::Ok );
} else {
defaultText = "Default Wishlist";
WishList wishlist( text );
if( wishlist.save() ) {
wishlistBox->addItem( text );
wishLists.push_back( wishlist ); //any method invoked by this object will cause the same error even .size()
} else {
QMessageBox::critical( this, "Error", "Could not create wishlist.", QMessageBox::Ok );
}
}
}
inputDialog->deleteLater();
}
我使用qDebug() << wishLists.size();
的行非常好。QList 本身已初始化,但为空。但是,当我使用 QList 的wishLists.push_back( wishlist );
或任何其他功能时,我会得到此错误:
ASSERT failure in QList<T>::at: "index out of range", file ../../../Qt5.5.1/5.5/gcc_64/include/QtCore/qlist.h, line 510
The program has unexpectedly finished.
这只是最近的错误。昨天完全没问题,没有对程序进行任何更改!每次我保存愿望清单并重新启动程序时,它都会将所有愿望清单读取到 qlist 中。因此,一旦列表中至少有 1 个项目,它就不会抛出此错误。
任何想法有什么问题?
更新:
0 __GI_raise /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.19.so 56 0x7ffff5d5acc9
1 __GI_abort /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.19.so 89 0x7ffff5d5e0d8
2 QMessageLogger::fatal(const char *, ...) const 0x7ffff669513e
3 qt_assert_x(const char *, const char *, const char *, int) 0x7ffff6690701
4 QList<WishList>::at qlist.h 510 0x40c725
5 MainWindow::updateListView mainwindow.cpp 204 0x408539
6 MainWindow::onWishlistChanged mainwindow.cpp 99 0x407c2e
7 MainWindow::qt_static_metacall moc_mainwindow.cpp 102 0x413520
8 QMetaObject::activate(QObject *, int, int, void * *) 0x7ffff68c335e
9 QComboBox::currentIndexChanged(int) 0x7ffff77be121
10 ?? 0x7ffff77c0451
11 ?? 0x7ffff77c26dd
12 QComboBox::setCurrentIndex(int) 0x7ffff77c294f
13 ?? 0x7ffff77c79d9
14 QMetaObject::activate(QObject *, int, int, void * *) 0x7ffff68c335e
15 QAbstractItemModel::rowsInserted(QModelIndex const&, int, int, QAbstractItemModel::QPrivateSignal) 0x7ffff693fd84
16 QAbstractItemModel::endInsertRows() 0x7ffff683fea2
17 ?? 0x7ffff71cd5bb
18 QComboBox::insertItem(int, QIcon const&, QString const&, QVariant const&) 0x7ffff77c3f18
19 QComboBox::insertItem qcombobox.h 268 0x4092a8
... <More>
看起来崩溃更有可能实际发生在:
wishlistBox->addItem( text );
由于调用堆栈位于某些与模型相关的更新代码中,因此您可能希望先添加到列表中:
wishLists.push_back( wishlist );
wishlistBox->addItem( text );
因为我没想到简单地修改 QList 会给出这样的调用堆栈。
相关文章:
- "error: no matching function for call to"构造函数错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 使用 LuaBridge 将 LuaJIT 绑定到C++会导致"PANIC: unprotected error"
- OpenMP卸载说'fatal error: could not find accel/nvptx-none/mkoffload'
- C++错误:"error: int aaa::bbb is protected within this context"
- 如何处理来自核心指南检查器的关于gsl::at的静态分析警告
- 尝试链接我的着色器时,我收到错误代码"error c5145 must write to gl_position"
- C++,在int数组中输入字符串或字符会输出0,而不是ascii或error
- 使用 cmake 的 LLVM 构建在 tsan_libdispatch_mac.cc 期间失败; "Error: conflicting types for ..."
- C++ "error: invalid use of void expression"
- struct.error:解压缩 C++ 结构时,解包需要 288 字节的缓冲区
- "CID"在AT+HTTPPARA= "CID" ,1中是什么意思
- 如何修复"error: ‘_1’ was not declared in this scope"?
- 从不同目录执行时"symbol lookup error:",否则从构建目录执行时按预期工作
- 在C++中使用 Catch 测试框架编译错误"error: expected ';' at end of declaration list"
- CMake Error at modules/videoio/cmake/detect_ffmpeg.cmake:16
- 使用模板时获取"Trigger Breakpoint Error at delete"
- CMake Error at cmake/modules/AddLLVM.cmake
- C++ - Qt Strange QList::at() error
- Mat::at - error:类型的非const引用的无效初始化的包装器