QT5 ASSERT failure in QList<T>
-
Hi, I compiled QT5 and QT Creator on windows 7 X64, and I'm having an annoying problem
when I create a project in QTCreator, everything works fine in both debug and release builds until I use the QTreeView widget (model based)
whenever I try to select the last item in the list I get the error "ASSERT failure in QList<T>::at: "index out of range", file c:\qt\x64\5.0.0\msvc2010\qtbase\include\qtcore../../src/corelib/tools/qlist.h, line 454, and this is not my apps only, every app I tried did this, even with the X86 QT version I downloaded from here, is this is a known bug ? , I new to qt btw.
Error:
http://www.freeimagehosting.net/7oeqxalso I noticed in QTCreator Application Output window this error whenever I select the last item in the list that has 10 items:
"Cannot creat accessible child interface for object: QTreeView(0x239cbd0, name = "treeView") index: 11"
the error says that index is 11, but the QModelIndex is 9, weird huh ?here is a simple code I wrote:
@
/////////////////////////////////////////
QStandardItemModel lstPrjModel;
QStandardItem *item;for(int i = 0; i < 10; i++)
{
item = new QStandardItem("item");
lstPrjModel.appendRow(item);
}
ui->treeView->setModel(&lstPrjModel);
///////////////////////////////////////////////@ -
welcome to devnet
please use "code wrappings":http://qt-project.org/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01 in your post. They make your code section better readable. I have introduced them for you.
Enjoy the holiday season.
-
Which line triggers the error? What apps have you tried?
Also, I'm wondering if your QStandardItemModel gets destroyed before your program finishes. Does it go out of scope while you're still accessing it with the QTreeView?
-
[quote author="focus-gfx" date="1356410056"]the error says that index is 11, but the QModelIndex is 9, weird huh ?[/quote]Memory corruption.
[quote]
@
QStandardItemModel lstPrjModel;
@
[/quote]HIskind and I hinted at the solution already. Change this line to:@
QStandardItemModel *lstPrjModel = new QStandardItemModel;
@
...and adjust your code (lines 8 and 10) to use pointers.In your original code, lstPrjModel gets destroyed when your function returns. You get an assert failure because the model and the list don't exist anymore.
[quote author="focus-gfx" date="1356649198"]also I should mention that this happen on debug build only[/quote]The problem is still there in the release build; lstPrjModel is still getting destroyed too early, and your memory is still getting corrupted. You just don't see an error message yet, because Q_ASSERT is disabled in release builds.
-
I changed the code to this, but the error is still there !
///////////////////////
//File: "mainwindow.h"
///////////////////////
@public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();QStandardItemModel *lstPrjModel; QStandardItem *item; void setupExtUi() { lstPrjModel = new QStandardItemModel; for(int i = 0; i < 10; i++) { item = new QStandardItem("item"); lstPrjModel->appendRow(item); } ui->treeView->setModel(lstPrjModel); }@
-
[quote author="focus-gfx" date="1356690490"]I changed the code to this, but the error is still there !
///////////////////////
//File: "mainwindow.h"
///////////////////////
@public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();QStandardItemModel *lstPrjModel; QStandardItem *item; void setupExtUi() { lstPrjModel = new QStandardItemModel; for(int i = 0; i < 10; i++) { item = new QStandardItem("item"); lstPrjModel->appendRow(item); } ui->treeView->setModel(lstPrjModel); }@
[/quote]
I copied this code, but I can't reproduce your problem in debug mode. I clicked on all the different items (including the last one), but my program didn't crash. I'm on Windows 8 x64, using the 32-bit version of Qt 5 for MSVC 2010 downloaded from http://qt-project.org/downloadsIf it's happening with all the examples too, then it sounds like there's something wrong with your Qt 5 DLLs. Maybe something went wrong when you compiled them. You can try compiling it again (after cleaning EVERYTHING), or you can trying downloading the precompiled version from the website.
Do you have multiple versions of Qt 5 on your computer?
-
Yes I have multiple version of QT
5.0.0 X64
5.0.0 X86
4.8.2 X86
and yes this error happens with the every example too, also happens with the X86 version I downloaded from the same location you provided.
now, this sounds like I have problems with my windows sdk debugging tools ? is that right or what ?
also I cleaned the qt compilation and recompiled it again three times but the errors stayed! -
Very very strange. I can't think of what is causing your problem, sorry.
But anyway, I compiled your example code (debug mode), and it works fine on my computer. See if it works for you: http://www.mediafire.com/download.php?5acd73i6ik670bp (just run bin\debug\treeview-bug-test.exe)
I'm using:
- Win 8 (64-bit)
- MSVC 2010 SP1 (32-bit)
- Official Qt 5.0.0 for Windows (32-bit), from this website
Some questions, to help troubleshoot your problem:
Are you using MSVC 2010 SP1?
When you tried the x86 version of Qt 5 from this website, did you use a 32-bit compiler?
Have you installed the latest version of Visual C++ 2010 redistributable?
Is Qt 5 in your PATH?
-
well, thank you for your time and effort to help me,
[Are you using MSVC 2010 SP1?]
Yes.[When you tried the x86 version of Qt 5 from this website, did you use a 32-bit compiler?]
yes and the error is still present.[Have you installed the latest version of Visual C++ 2010 redistributable?]
yes.[Is Qt 5 in your PATH?]
of course as I compiled it myself.your build gives me this error when I try to run it
http://www.freeimagehosting.net/gqquu -
You're welcome :)
[quote]your build gives me this error when I try to run it
http://www.freeimagehosting.net/gqquu[/quote]
Whoops, forgot one DLL: http://www.mediafire.com/?g8umndrd65gnjzmCopy the DLL to bin\debug\platforms\qwindowsd.dll
[quote author="focus-gfx" date="1356782871"][Is Qt 5 in your PATH?]
of course as I compiled it myself.[/quote]Your compiler seems fine, but I'm wondering if your computer was loading the wrong version of Qt (when you had multiple versions).Anyway, try my test app again. Temporarily rename your Qt folder (to move it away from your PATH) -- this is to make sure that your computer uses the DLLs that I uploaded.