Results 1 to 7 of 7

Thread: Not accessing widget outside the class

  1. #1
    Join Date
    May 2007
    Posts
    110
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Not accessing widget outside the class

    Hi
    i m creating one dialog using designer...dialog conatins one treeWidget.
    I m making this this dialog as public...

    Ui:ialog dlg;

    In the construtor i m calling setupUi(this); its working....

    but i want to use this treeWidget in other class...i m using obj of this class...

    obj->dlg.treeWidget in other class...but its not working...where m i missing...

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Not accessing widget outside the class

    Well, how exactly are you using it? Is it in other thread?
    Is the dialog created( setupUi and all ) when you use it?
    Could you post some relevant code?

  3. #3
    Join Date
    May 2007
    Posts
    110
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Not accessing widget outside the class

    some code for this ...
    //first file
    #include "ui_Dialog.h"

    Header file
    public:
    Ui:ialog dlg;

    cpp file
    Constructor part of FIRST class
    {
    dlg.setupUi(this);
    dlg.treeWidget->setColumnCount(2);
    }

    ///Second class
    header class
    private:
    FIRST *first;
    //cpp file
    void SECOND::func()
    {
    QTreeWidgetItem *pItem = NULL;
    pItem = new QTreeWidgetItem(first->dlg.treeWidget);
    pItem->setText(0,"root");
    }


    ///But is not connecting to the FIRST class...not display text "root" in treeWidget ...why

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Not accessing widget outside the class

    The problem is that you did not instantiate FIRST in the SECOND class.
    You have to create FIRST to be able to use it like that. Something like:
    first = new FIRST();

  5. #5
    Join Date
    May 2007
    Posts
    110
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Not accessing widget outside the class

    i already instantialted like this in my class

    first = new FIRST();
    still it is not working....

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Not accessing widget outside the class

    In the constructor of FIRST:
    it is setupUi( this ) not dlg.setupUi( this ).

    If you get any errors after replacing that, please post them

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Not accessing widget outside the class

    Quote Originally Posted by santosh.kumar View Post
    still it is not working....
    What does "not working" exactly mean in this case? Does it compile?

    Quote Originally Posted by marcel View Post
    In the constructor of FIRST:
    it is setupUi( this ) not dlg.setupUi( this ).
    The original version was OK, as santosh.kumar uses the single inheritance approach.

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.