Results 1 to 6 of 6

Thread: Can't compile QList<struct>

  1. #1
    Join Date
    Oct 2015
    Posts
    50
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Question Can't compile QList<struct>

    Hi,

    in my Header mainwindow.h i declare a struct and a QList inside my MainWindow class.
    Qt Code:
    1. private:
    2. ....
    3. struct Parameterlevel{
    4. QString Levelname;
    5. quint8 Levelindex;
    6. quint8 Securitylevel;
    7. ....
    8. QList<Parameterlevel> TabList;
    9. };
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Can't compile QList<struct>

    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,
    _

  3. #3
    Join Date
    Oct 2015
    Posts
    50
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Can't compile QList<struct>

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Can't compile QList<struct>

    Ah, you said "I can't compile the code" which usually means there is an error.

    Cheers,
    _

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Can't compile QList<struct>

    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

    Qt Code:
    1. QList<ParameterLevel> TabList;
    To copy to clipboard, switch view to plain text mode 

    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).
    Last edited by d_stranz; 3rd November 2015 at 21:51.

  6. #6
    Join Date
    Oct 2015
    Posts
    50
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Can't compile QList<struct>

    Okay I don't know how but I solved the problem. Thank You.

Similar Threads

  1. QList<struct>
    By Axsis in forum Newbie
    Replies: 11
    Last Post: 12th October 2015, 07:48
  2. Replies: 2
    Last Post: 8th May 2014, 09:28
  3. remove struct from qlist
    By mero in forum Qt Programming
    Replies: 2
    Last Post: 26th October 2012, 14:58
  4. How to fill a QList<struct> ?
    By falconium in forum Newbie
    Replies: 1
    Last Post: 1st March 2011, 21:59
  5. Qt 3 to Qt 4 port: QList compile errors
    By Amanda in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2006, 05:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.