Results 1 to 3 of 3

Thread: How accessing a member of a Widget in a QList?

  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How accessing a member of a Widget in a QList?

    Hi,
    I have created a new widget and called it MyWidget (it includes some qcomboboxes and some qlabels); then I have created a QList like this:

    Qt Code:
    1. QList<QWidget *> myList;
    To copy to clipboard, switch view to plain text mode 

    and appended 2 myWidget:

    Qt Code:
    1. myWidget_1 = new MyWidget;
    2. myWidget_2 = new MyWidget;
    3. myList.append(myWidget_1);
    4. myList.append(myWidget_2);
    To copy to clipboard, switch view to plain text mode 

    Now, how can i access a combobox in one of myWidget? The following code gives error during compilation (error: ‘class QWidget’ has no member named ‘comboBox’):

    Qt Code:
    1. int index = myList.at(0)->comboBox->currentIndex();
    To copy to clipboard, switch view to plain text mode 


    Regards
    Giuseppe CalÃ

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How accessing a member of a Widget in a QList?

    As the error message states, QWidget has no such member. You should store MyWidget pointers if you want to access MyWidget members:
    Qt Code:
    1. QList<MyWidget*> myList;
    To copy to clipboard, switch view to plain text mode 
    PS. You should try to avoid public variables
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    jiveaxe (31st October 2007)

  4. #3
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How accessing a member of a Widget in a QList?

    Thank's jpn,
    now works.

    Bye
    Giuseppe CalÃ

Similar Threads

  1. accessing my main application window widget
    By jayw710 in forum Newbie
    Replies: 8
    Last Post: 15th November 2007, 19:33
  2. Not accessing widget outside the class
    By santosh.kumar in forum Qt Programming
    Replies: 6
    Last Post: 18th May 2007, 12:57
  3. accessing prtected member of QTableView
    By locus in forum Qt Programming
    Replies: 1
    Last Post: 29th January 2007, 20:30
  4. Accessing QList Objects
    By magikalpnoi in forum Qt Programming
    Replies: 7
    Last Post: 21st September 2006, 20:43

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.