PDA

View Full Version : Can't compile QList<struct>



mikrocat
3rd November 2015, 11:39
Hi,

in my Header mainwindow.h i declare a struct and a QList inside my MainWindow class.

private:
....
struct Parameterlevel{
QString Levelname;
quint8 Levelindex;
quint8 Securitylevel;
....
QList<Parameterlevel> TabList;
};

I want to create a list where I can add the Parameterlevels later but if I put the declaration of the List in my header, I can't compile the code. My program crashes. If the declaration of the list is in the .cpp there seems to be no problem with it.
Where is my mistake?

anda_skoa
3rd November 2015, 11:55
So you have a struct in the private part of a class declaration and in the same private section you have a QList of that struct, correct?
That should work, what is the error you are getting?

Cheers,
_

mikrocat
3rd November 2015, 12:03
Yes it should. I tried it in a complete new project now and it works fine. But in my it doesn't work. There is no error, no warning. The program crashes before start and if i put the QList declaration in a comment, it works. :mad::mad::mad:

anda_skoa
3rd November 2015, 12:58
Ah, you said "I can't compile the code" which usually means there is an error.

Cheers,
_

d_stranz
3rd November 2015, 22:46
if i put the QList declaration in a comment, it works.

Which means you are not referencing that QList<> variable *anywhere else* in your MainWindow code, right? Otherwise, the code wouldn't compile in the first place.

By any chance did you mistakenly add the line


QList<ParameterLevel> TabList;

somewhere in your MainWindow constructor (thus declaring a variable *local* to the scope of the constructor that hides the member variable of the same name)? If so, then your member variable remains unchanged, and if you try to access something from it, you get a segmentation fault and a crash.

Please teach yourself the meanings of "compiling", "linking", and "executing" code. If code doesn't compile, you have no compiled objects and nothing to link. If compiled objects don't link, then you have nothing to execute. Only once you get a correctly compiled and linked executable do you have something to run (and possibly crash).

mikrocat
4th November 2015, 07:04
Okay I don't know how but I solved the problem. :confused: Thank You.