Results 1 to 4 of 4

Thread: QLabel pointer - seg fault

  1. #1
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    70
    Thanked 7 Times in 6 Posts

    Default QLabel pointer - seg fault

    Hello!

    I've got some problems with QLabel and pointers. I've created window with 4 labels. Then in my include file I've got something like this:

    Qt Code:
    1. class app : public QDialog
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. [...]
    7.  
    8. public slots:
    9. [..]
    10.  
    11. private:
    12. QLabel *myLabels[4];
    13. };
    To copy to clipboard, switch view to plain text mode 

    In app.cpp I've got:

    Qt Code:
    1. [...]
    2. {
    3. ui->setupUi(this);
    4. [...]
    5.  
    6. myLabels[0]=ui->label1;
    7. myLabels[1]=ui->label2;
    8. myLabels[2]=ui->label3;
    9. myLabels[3]=ui->label4;
    10. }
    To copy to clipboard, switch view to plain text mode 

    And then I've got function:

    Qt Code:
    1. bool app::myFunc()
    2. {
    3. for (int i=0; i<4; i++)
    4. {
    5. myLabels[i]->setText( "test" );
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

    And myFunc() causes segmentation fault. Any idea why?

    When I do:
    Qt Code:
    1. ui->label1->setText( "test" );
    To copy to clipboard, switch view to plain text mode 

    Everything is OK.

    thanks in advance
    best regards
    Tomasz
    Last edited by Tomasz; 26th November 2010 at 15:50.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QLabel pointer - seg fault

    Please provide a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    18
    Thanked 68 Times in 66 Posts

    Default Re: QLabel pointer - seg fault

    maybe you forgot to initialize your array?

    maybe you call myFunc before assigning the labels to the array?

  4. The following user says thank you to FelixB for this useful post:

    Tomasz (28th November 2010)

  5. #4
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    70
    Thanked 7 Times in 6 Posts

    Default Re: QLabel pointer - seg fault

    Quote Originally Posted by FelixB View Post
    maybe you call myFunc before assigning the labels to the array?
    I've analysed my code, and You're right. My stupid mistake.

    thanks
    best regards
    Tomasz

Similar Threads

  1. QLabel and Mouse pointer Issue
    By newb in forum Qt Programming
    Replies: 3
    Last Post: 24th July 2010, 12:31
  2. Replies: 1
    Last Post: 29th September 2009, 20:44
  3. Replies: 1
    Last Post: 2nd August 2008, 16:46
  4. [SOLVED] QLabel and Segmentation fault...
    By Lykurg in forum Qt Programming
    Replies: 5
    Last Post: 4th October 2007, 14:12
  5. Seg fault, but why?
    By Lykurg in forum Newbie
    Replies: 5
    Last Post: 8th March 2007, 23:49

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.