Results 1 to 18 of 18

Thread: Accessing objects in different forms

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Accessing objects in different forms

    I suggest you use the method wysota has suggested. I think it a cleaner way to accomplish your task.

    If you still want to use the other way and know what the error is, can you please show us your code ?

  2. #2
    Join Date
    Apr 2006
    Location
    Slovenia
    Posts
    33
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Accessing objects in different forms

    In povezava.ui.h I have:
    Qt Code:
    1. void Povezava::Connect_clicked()
    2. {
    3. .
    4. .
    5. .
    6. GlavnoO->enable_lista_tabel();
    7. close();
    8.  
    9. };
    To copy to clipboard, switch view to plain text mode 

    In GlavnoO.ui.h I have:
    Qt Code:
    1. void GlavnoO::enable_lista_tabel()
    2. {
    3. lista_tabel->setEnabled(true);
    4. };
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2006
    Location
    Slovenia
    Posts
    33
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Accessing objects in different forms

    I think I know where the problem is: GlavnoO is class while I would need to call object of that class. The problem is that I have that object defined in main.cpp and I don't know how to include it.

  4. #4
    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: Accessing objects in different forms

    Quote Originally Posted by Lebowski
    The problem is that I have that object defined in main.cpp and I don't know how to include it.
    You can use signals and slots mechanism to connect those two objects.

  5. #5
    Join Date
    Apr 2006
    Location
    Slovenia
    Posts
    33
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Accessing objects in different forms

    I already have a slot defined:
    Qt Code:
    1. void GlavnoO::enable_lista_tabel()
    2. {
    3. lista_tabel->setEnabled(true);
    4. };
    To copy to clipboard, switch view to plain text mode 

    How do I create signal in designer? Just adding it in Object Explorer doesn't generate anything really. And adding it to .h file in ".ui/" folder won't work cause all changes there are being ignored.
    Last edited by Lebowski; 12th April 2006 at 12:55.

  6. #6
    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: Accessing objects in different forms

    Quote Originally Posted by Lebowski
    How do I create signal in designer? Just adding it in Object Explorer doesn't generate anything really.
    You don't implement signals --- it's enough to declare them within class definition (the rest will be handled by moc).

    Then just write:
    Qt Code:
    1. emit someSignal( someParameter );
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by Lebowski
    And adding it to .h file in ".ui/" folder won't work cause all changes there are being ignored.
    Then try the subclassing approach: http://doc.trolltech.com/3.3/designer-manual-6.html

  7. #7
    Join Date
    Apr 2006
    Location
    Slovenia
    Posts
    33
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Accessing objects in different forms

    Quote Originally Posted by jacek
    You don't implement signals --- it's enough to declare them within class definition (the rest will be handled by moc).

    Then just write:
    Qt Code:
    1. emit someSignal( someParameter );
    To copy to clipboard, switch view to plain text mode 
    Is it enough to just write that line of code in (for example) my povezava.ui.h file within some function (slot)?

  8. #8
    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: Accessing objects in different forms

    Quote Originally Posted by Lebowski
    Is it enough to just write that line of code in (for example) my povezava.ui.h file within some function (slot)?
    Yes, if you have declared that signal in the Designer. Of course you will also have to make the connection.

  9. #9
    Join Date
    Apr 2006
    Location
    Slovenia
    Posts
    33
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Accessing objects in different forms

    Signal and slot are now working ok. Thanx for help.

    Where do I make connection though? In main.cpp? Cause QT Designer's wizard only allows creation of connections within same form.

  10. #10
    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: Accessing objects in different forms

    Quote Originally Posted by Lebowski
    Where do I make connection though? In main.cpp? Cause QT Designer's wizard only allows creation of connections within same form.
    You will have to create the connection by hand. The best place to do it is the one where you have an easy access to both objects, in your case this might be the main() function.

  11. The following user says thank you to jacek for this useful post:

    Lebowski (13th April 2006)

  12. #11
    Join Date
    Apr 2006
    Location
    Slovenia
    Posts
    33
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Accessing objects in different forms

    It works!!! Thanx a lot
    Btw in connect I had to use '&' character in front of object names. What does that mean? Does it mean memory address of that object maybe?

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Accessing objects in different forms

    Yes. Connect needs pointers.

Similar Threads

  1. Accessing QList Objects
    By magikalpnoi in forum Qt Programming
    Replies: 7
    Last Post: 21st September 2006, 20:43
  2. accessing form1's objects from form2
    By Philip_Anselmo in forum Newbie
    Replies: 5
    Last Post: 4th May 2006, 22:54

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.