Okay.. this one is proving to be tricky. I'll try to supply as much info as possible without giving out company code. First,
The necessary particulars:
OS: Windows 7 x64
Proc: Dual-Core AMD Opteron 2218 2.60GHz (2 processors)
RAM: 8GB
Qt: 4.8.0
IDEs: VS2010 Professional, Qt Creator 2.4.1
The Problem:
When running my project in Debug mode via VS2010, the application occasionally crashes after a minute or two when drawing a QTreeWidget to the main interface. Please NOTE: I cannot reproduce this bug when launching from the Qt Creator IDE. This bug is not the immediate effect of a SIGNAL/SLOT connection. However, I have been able to strongly suspect that when I pull out code that modifies the QTreeWidget then the crash bug disappears. Unfortunately, the program is fickle as to when it will crash when the supposedly offensive code is present.
The code is outlined as follows:
Interface class has a member of engine class. Engine class has a member of QTreeWidget and data class. QTreeWidget is not kept with interface class because it is directly driven by data class, which is only accessible in the engine class. The engine class performs all processing functions, or calls or functions to perform processing; the interface class only makes requests to the engine class via SIGNAL/SLOT connections.
The CTor for the Engine Class:
|
Source code
|
1
2
3
4
5
6
|
Engine::Engine(QWidget *parent)
{
parentWidget = parent;
data = new Data();
BuildTreeWidget();
}
|
The BuildTreeWidget Function that will often produce the "Access violation reading location..." error
|
Source code
|
1
2
3
4
5
6
7
8
9
10
|
void Engine::BuildTreeWidget()
{
projectLister = new QTreeWidget(parentWidget);
projectLister->setColumnCount(1);
QList<QTreeWidgetItem *> items;
for (int i = 0; i < 10; i++)
items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("item: %1").arg(i))));
projectLister->insertTopLevelItems(0, items);
projectLister->setHeaderLabel("");
}
|
The BuildTreeWidget Function that will NOT produce the "Access violation reading location..." error
|
Source code
|
1
2
3
4
5
6
7
8
9
10
|
void Engine::BuildTreeWidget()
{
projectLister = new QTreeWidget(parentWidget);
projectLister->setColumnCount(1);
//QList<QTreeWidgetItem *> items;
//for (int i = 0; i < 10; i++)
// items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("item: %1").arg(i))));
//projectLister->insertTopLevelItems(0, items);
//projectLister->setHeaderLabel("");
}
|
Additional Details:
It may help to know that I am running the VS2010 and Qt Creator projects from the same code base. Both have their project files in the same directories and both compile the exact same code. The purpose of doing this? I like coding in VS2010 better, but I need the OS portability of cross-platform Qt compiling.
Finally...
Your assistance in this matter is much appreciated. I attempted to review similar articles in this forum about the "Access violation reading location blah blah blah" error and while the information was often useful, it didn't seem useful in this matter. My one thought on the matter would be that if I define the QList<QTreeWIdgetItem*> items as a member of the Engine class itself, then perhaps the data wouldn't get deleted when the "BuildTreeWidget" function ends and that perhaps the application is crashing because Qt occasionally checks the QTreeWidget object for valid member data. This guess might also be a pile of hooey, or malarkey.
Thank You,