You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

Pipeliner

Beginner

  • "Pipeliner" started this thread

Posts: 24

Location: Los Angeles

Occupation: Tools Developer

  • Send private message

1

Saturday, June 16th 2012, 12:28am

Non-constant "Accesss violation reading location 0xfffffffffffff" crash error

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,
Pipeliner has attached the following file:

2

Saturday, June 16th 2012, 9:32am

as your code is exact copy of Qt example, except for
projectLister = new QTreeWidget( parentWidget );
I would ask :
is parent argument passed to Engine constructor correctly initialized ?

3

Saturday, June 16th 2012, 10:15am

you say you cannot reproduce when launching from qt creator - does this include the case where you have built from msvs, and then launched from creator?
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Pipeliner

Beginner

  • "Pipeliner" started this thread

Posts: 24

Location: Los Angeles

Occupation: Tools Developer

  • Send private message

4

Monday, June 18th 2012, 6:22pm

as your code is exact copy of Qt example, except for
projectLister = new QTreeWidget( parentWidget );
I would ask :
is parent argument passed to Engine constructor correctly initialized ?

Below is the "setupUI" function for the interface class. Here you can see the passing of the parent widget from interface class to engine class. Below this code snippet is the CTor of the engine class, which stores the parentWidget as a member of the class.

Source code

1
2
3
4
5
6
7
8
9
10
void Ui_ProjectMakerClass::setupUi(QMainWindow *ProjectMakerClass)
{

	if (ProjectMakerClass->objectName().isEmpty())
    	ProjectMakerClass->setObjectName(QString::fromUtf8("ProjectMakerClass"));
	ProjectMakerClass->resize(1000, 600);
	centralWidget = new QWidget(ProjectMakerClass);
	centralWidget->setObjectName(QString::fromUtf8("centralWidget"));

	engine = new Engine(centralWidget);


Engine Class Definition snippet declaring the ownership of the parent widget item...

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Engine : public QObject
{
	Q_OBJECT

public:
	Engine(QWidget *parent); //public ctor
	~Engine(); //dtor

//functions - public
	QString Get_VersionInfo();
	
//members - public
	QTreeWidget *projectLister;


private:
	// Functions - private
	Engine(const Engine &rhs);
	Engine &operator=(const Engine &rhs);

	Error ProjectRootSelect();
	Error IsProjectFileValid(QString &pathIN);
	Error CheckForProjectFile(QString &pathIN);
	void BuildTreeWidget();

	void SetProjectName(QString nameIN);

	// Members - Private
	Data *data;
	QWidget *parentWidget;


The CTor Definition code for Engine.cpp

Source code

1
2
3
4
5
6
Engine::Engine(QWidget *parent)
{
	parentWidget = parent; //stores parentWidget pointer in Engine class
	data = new Data();
	BuildTreeWidget(); //Called after parentWidget pointer is stored in Engine class
}


Passing of the parentWidget to the QTreeWidget object

Source code

1
2
3
4
5
6
7
8
9
10
void Engine::BuildTreeWidget()
{
	projectLister = new QTreeWidget(parentWidget); //parentWidget is assigned from stored pointer in class
	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("");
}

Pipeliner

Beginner

  • "Pipeliner" started this thread

Posts: 24

Location: Los Angeles

Occupation: Tools Developer

  • Send private message

5

Monday, June 18th 2012, 6:30pm

you say you cannot reproduce when launching from qt creator - does this include the case where you have built from msvs, and then launched from creator?
Oddly enough, when I build to "Qt 4.8.0 for Desktop - MSVC2010 (Qt SDK) Debug" or to "Qt 4.8.0 (4.8.0) Debug" I do not receive the same crash bug, nor any crash. The attached image is shows my build environments.

Below is my .pro file

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#-------------------------------------------------
#
# Project created by QtCreator 2012-05-14T12:23:47
#
#-------------------------------------------------

QT       += core gui

TARGET = ProjectMaker
TEMPLATE = app

INCLUDEPATH += Code/Header \
    Code/Source \
    Code/Resource

SOURCES += main.cpp \
    Code/Source/projectmaker.cpp \
    Code/Source/ui_projectmaker.cpp \
    Code/Source/Error.cpp \
    Code/Source/Engine.cpp \
    Code/Source/Data.cpp

HEADERS  += Code/Header/projectmaker.h \
    Code/Header/NamingTranslator.h \
    Code/Header/ui_projectmaker.h \
    Code/Header/Error.h \
    Code/Header/Engine.h \
    Code/Header/Data.h

OTHER_FILES += \
    Reference/ShotNameParser_PseudoCode.txt

RESOURCES += \
    Code/Resource/projectmaker.qrc
Pipeliner has attached the following file:

Pipeliner

Beginner

  • "Pipeliner" started this thread

Posts: 24

Location: Los Angeles

Occupation: Tools Developer

  • Send private message

6

Monday, June 18th 2012, 6:31pm

It has occurred to me that I might need to rebuild my Qt library that VS2010 compiles from.
Is this logic sound?

7

Monday, June 18th 2012, 6:45pm

what compiler does 'Qt 4.8.0 (4.8.0) Debug' use.
Is that the one that causes the problem code when you try to debug with msvs? I'm sure you can see where this is going... :)

If you use Qt library with two different compilers, then yes, of course you will need different builds of the libraries.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Pipeliner

Beginner

  • "Pipeliner" started this thread

Posts: 24

Location: Los Angeles

Occupation: Tools Developer

  • Send private message

8

Monday, June 18th 2012, 7:07pm

what compiler does 'Qt 4.8.0 (4.8.0) Debug' use.
Is that the one that causes the problem code when you try to debug with msvs? I'm sure you can see where this is going... :)

If you use Qt library with two different compilers, then yes, of course you will need different builds of the libraries.

Alright... this is where my understanding starts to get a little fuzzy. If my questions or answers start to seem a little bizarre or lacking in pertinent information I'll be happy to read any section of the Qt documentation required or recommended.

I have two builds of the Qt API
  • c:\qtsdk\desktop\qt\4.8.0\msvc2010
  • c:\qt\4.8.0
The Qt Creator 2.4.1 IDE can compile the code from both of the Qt APIs and run it without issue.
VS2010 compiles from the c:\qt\4.8.0 API

The build steps for the Qt Creator IDE, with the c:\qt\4.8.0\ API, are as follows:

Source code

1
2
qmake.exe E:\Tools\MAGI\AdminTools\ProjectMaker\ProjectMaker.pro -r -spec win32-msvc2010 "CONFIG+=declarative_debug"
jom.exe in E:\Tools\MAGI\AdminTools\ProjectMaker-build-desktop-Qt_4_8_0__4_8_0__Debug


I thought I knew where this was going but now that the app hasn't crashed from either IDE in a few days, maybe I just forgot to clean my build before rebuilding? It seems like a rookie mistake but I'd prefer that over a small, nefarious error in the build process of the API.

I'll keep you posted should anything else arise...

Pipeliner

Beginner

  • "Pipeliner" started this thread

Posts: 24

Location: Los Angeles

Occupation: Tools Developer

  • Send private message

9

Monday, June 18th 2012, 7:37pm

The Qt Creator 2.4.1 IDE can compile the code from both of the Qt APIs and run it without issue.
VS2010 compiles from the c:\qt\4.8.0 API
One thing that might make a difference...
I just noticed that while the Qt Creator IDE is successfully compiling the code from both 4.8.0 API locations, it is using the same compiler in the tool chain:
  • Microsoft Windows SD for Windows 7 (7.1.7600.0.30514) (x86)
If I do get continued discrepancies in the compiling of an application, I'll try switching the Qt Creator Toolchain to use the VS C++ Compiler and see what happens.
Pipeliner has attached the following file:

10

Tuesday, June 19th 2012, 12:13am

Why do you have two builds of qt but only (intend to) use one compiler?

I use the VS compiler in creator and dont have any problems, although I cant recall how you would configure it to use your VS ones, and not the sdk ones.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Pipeliner

Beginner

  • "Pipeliner" started this thread

Posts: 24

Location: Los Angeles

Occupation: Tools Developer

  • Send private message

11

Tuesday, June 19th 2012, 12:18am

I installed c:\qt\4.8.0 for use with VS2010. I did this first, before installing Qt Creator, so I could get coding with VS2010. When the requirement for cross platform arose, I installed the QtSDK because it was the only way I could figure out how to get Qt Creator installed (as well as the other Qt Tools that now seem discontinued and have since been rolled in to QtCreator). When originally building this machine it wasn't my intention to have two separate builds of Qt.
So, in short, no deftly compelling reason I assure you.

Pipeliner

Beginner

  • "Pipeliner" started this thread

Posts: 24

Location: Los Angeles

Occupation: Tools Developer

  • Send private message

12

Tuesday, June 19th 2012, 12:26am

Also, technically speaking, since I'm using VS2010 and Qt Creator, they each are different compilers.
I code and get everything working in VS2010, then check that it works in Qt Creator, then port to a different OS where I test the build (usually without error at this point) and can then publish and build for that specific hardware and OS config.

13

Tuesday, June 19th 2012, 8:31am

Just because you use Qt Creator doesnt mean it uses a different compiler. If it is using a different compiler then that is a definite problem.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Pipeliner

Beginner

  • "Pipeliner" started this thread

Posts: 24

Location: Los Angeles

Occupation: Tools Developer

  • Send private message

14

Tuesday, June 19th 2012, 6:25pm

Is it the type of problem that would prohibit building the project altogether?

15

Tuesday, June 19th 2012, 6:50pm

between two different companies' compilers/linkers - probably, although not definitely. (thinking about mangling rules here)

How compatible different versions of compilers are from the same company, I don't know. ie I don't know if a mismatch build will just not complete, or if you will end up with an app that does funny things.

It IS a problem, though, since there are different 'installable' Qt binaries for studio 2005, 2008, etc (commercial product).
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Pipeliner

Beginner

  • "Pipeliner" started this thread

Posts: 24

Location: Los Angeles

Occupation: Tools Developer

  • Send private message

16

Tuesday, June 19th 2012, 6:57pm

Right... the c:\qt\4.8.0 build was done specifically for, and by, the VS2010 command prompt (as outlined in some of the fine documents on the subject)
The c:\qtsdk\desktop\qt\4.8.0\ was installed at the same time Qt Creator was installed, and has been used by that IDE

The bug I've been having has been with the c:\qt\4.8.0 build (built by VS2010 command line prompt) and only when the app is being compiled by the VS2010 compiler. So, it's the same toolchain created by and for the same IDE where the problem is occuring when compiled by the same IDE.
When using Qt Creatore IDE in either toolchain the problem does not arise.

17

Tuesday, June 19th 2012, 10:47pm

i'm all out of ideas.

Unless you have both library locations on your PATH and studio is linking with the wrong version.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Pipeliner

Beginner

  • "Pipeliner" started this thread

Posts: 24

Location: Los Angeles

Occupation: Tools Developer

  • Send private message

18

Tuesday, June 19th 2012, 11:21pm

Do you think it could be that the variable wasn't declared as a member of the class but instead existed only inside the function? I'm not sure what type of copying Qt does in this scenario when assigning QList<QTreeWidgetItems*> items to the QTreeWidget. Are they copied inside the QTreeWidget and therefore the initial variable is unnecessary once the data is assigned?
If this does pop up again I'll try making the QList<QTreeWidgetItem*> items a member of the class and hope that since they will be class members they will therefore not get destroyed upon function exit.

Thoughts?

Thanks for your continued insight and input here. It is very appreciated and very educational.

19

Wednesday, June 20th 2012, 8:12am

no, it wont because that list is a non-member. Qt will just be grabbing the pointers.

If I was going to try anything, it would be to remove the QStringList temporary from the append(...) call and make it an lvalue on the line above.

edit:
OOh, like like that ^^ suggestion should do the trick!
I've just found this!!

Quoted


The second context is when a reference is bound to a temporary. The temporary to which the reference is bound or the temporary that is the complete object to a subobject of which the temporary is bound persists for the lifetime of the reference except as specified below. A temporary bound to a reference member in a constructor’s ctor-initializer (12.6.2) persists until the constructor exits. A temporary bound to a reference parameter in a function call (5.2.2) persists until the completion of the full expression containing the call.

http://stackoverflow.com/questions/27842…-of-a-temporary
which means your stringlist dies before append(...) gets it, according to the standard. Your code is relying on non-standard/undefined behaviour! :)

Hopefully that is the end of that!

Sorry to have taken you around the houses with a load to tool chain/compiler queries.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

This post has been edited 3 times, last edit by "Amleto" (Jun 20th 2012, 8:22am)


Pipeliner

Beginner

  • "Pipeliner" started this thread

Posts: 24

Location: Los Angeles

Occupation: Tools Developer

  • Send private message

20

Thursday, June 21st 2012, 12:56am

That was a great article, and also the article that someone linked to from there about the local const prolonging the life of the rvalue. Here's the article: gotw-88-a-candidate-for-the-most-important-const/

And no worries about the compiler/tool chain questions. It gave me a chance to make sure all my 'i's were dotted and the 't's crossed. I've been working long enough to know that quality discussions can yield unexpected results; so I researched what I could and learned along the way. That the answer was somewhere else only means that I learned more till we got there.
I have since moved those members to the class and have encountered no problems.

Thanks for the help!

Similar threads

Used tags

QTreeWidget