Results 1 to 3 of 3

Thread: Segmentation Fault possiby related to positioning of variable near Q_OBJECT

  1. #1
    Join Date
    Nov 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    26
    Thanked 1 Time in 1 Post

    Default Re: Segmentation Fault possiby related to positioning of variable near Q_OBJECT

    Hi,
    I'm getting a crash at the start of my GUI application that is apparently connected to the declaration of a member variable close to the Q_OBJECT macro.

    At first the application runs fine. But once I add the line
    Qt Code:
    1. CaseData* cdata;
    To copy to clipboard, switch view to plain text mode 
    in the following code of the MainWindow class' declaration:

    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. CaseMenu* cm;
    6. Parameter_Menu* pm;
    7.  
    8. //CaseData* cdata;
    9.  
    10. public:
    11. explicit MainWindow(QWidget *parent = 0);
    12. ~MainWindow();
    13.  
    14. [..]
    15.  
    16. private:
    17. Ui::MainWindow *ui;
    To copy to clipboard, switch view to plain text mode 

    then the application crashes right after being started up with a "Segmentation Fault by signal SIGSEGV", with the debugger pointing to the first constructor line where the first item ('pm') is constructed.

    The application output shows lots of copies of this message:
    "Internal error: pc 0x0 in read in psymtab, but not in symtab."
    This is all independent from actually using the variable 'cdata' anywhere.

    If I instead place the declaration further down to where the *ui pointer is declared, the application works. But only as long as I don't try to use the variable by e.g. initializing it in the constructor.
    Then I get the same crash, but not the repeating line
    "Internal error: pc 0x0 in read in psymtab, but not in symtab."
    during debugging.

    I wonder if I'm allowed to place variable declarations below the Q_OBJECT macro. I did this in the other classes that use Q_OBJECT and are created by MainWindow and I had no problems there.

    I'm using a Windows Vista Notebook with Qt 4.7.1 (32 bit) and Qt Creator 2.1.0


    Added after 1 13 minutes:


    A Make Clean solved it.
    Last edited by Computer Hater; 13th July 2011 at 02:03.
    Hint: Think carefully before picking a user name.

  2. #2
    Join Date
    May 2011
    Posts
    239
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60
    Thanks
    4
    Thanked 35 Times in 35 Posts

    Default Re: Segmentation Fault possiby related to positioning of variable near Q_OBJECT

    Even if you were allowed to place your variables there, why would you? You are missing a visibility declaration for the variables (public, protected etc.) and the compiler may not know what to do with them.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Segmentation Fault possiby related to positioning of variable near Q_OBJECT

    They will be private if placed in a class without a preceding public or protected access specifier. If placed in a struct they are public by default.

    The location of Q_OBJECT macros just inside the class definition makes the inserted code private (a requirement).

Similar Threads

  1. segmentation fault!!
    By Yayati.Ekbote in forum Qt Programming
    Replies: 4
    Last Post: 24th March 2010, 16:10
  2. Segmentation Fault
    By jmc in forum Qt Tools
    Replies: 4
    Last Post: 24th February 2010, 21:08
  3. segmentation fault
    By navid in forum Qt Programming
    Replies: 3
    Last Post: 20th December 2009, 12:40
  4. segmentation fault
    By uchennaanyanwu in forum Newbie
    Replies: 3
    Last Post: 31st July 2008, 17:52
  5. Segmentation Fault
    By Krish_ng in forum Qt Programming
    Replies: 8
    Last Post: 7th August 2007, 11:49

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.