Results 1 to 4 of 4

Thread: QLabel pointer - seg fault

Threaded View

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

    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 14:50.

Similar Threads

  1. QLabel and Mouse pointer Issue
    By newb in forum Qt Programming
    Replies: 3
    Last Post: 24th July 2010, 11:31
  2. Replies: 1
    Last Post: 29th September 2009, 19:44
  3. Replies: 1
    Last Post: 2nd August 2008, 15:46
  4. [SOLVED] QLabel and Segmentation fault...
    By Lykurg in forum Qt Programming
    Replies: 5
    Last Post: 4th October 2007, 13:12
  5. Seg fault, but why?
    By Lykurg in forum Newbie
    Replies: 5
    Last Post: 8th March 2007, 22: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.