Results 1 to 4 of 4

Thread: How to call to variables of another form

  1. #1
    Join Date
    Apr 2010
    Location
    Rzeszów \ Poland
    Posts
    26
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default How to call to variables of another form

    Hello!
    I want to assign any variables for example from MainWindow to another, but I don't know how to do it.

    I try this:
    Qt Code:
    1. MainWindow *main = new MainWindow;
    To copy to clipboard, switch view to plain text mode 
    in another form.
    I know how to call any objects in ui, but don't know how call to any variable.

    Thanks

  2. #2
    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: How to call to variables of another form

    Those objects are also variables so you refer to any variables the same way as to widgets.
    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
    Apr 2010
    Location
    Rzeszów \ Poland
    Posts
    26
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: How to call to variables of another form

    Can you give ma any example code?

  4. #4
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to call to variables of another form

    Ther are lots of ways, here is one:
    Qt Code:
    1. myobj->foo = main->bar; // assuming foo & bar are compatible types and bar is not declared private or protected inside main.
    To copy to clipboard, switch view to plain text mode 

    It is however better to use get() and set() type member functions or you may end up with unmanageable code.
    Got to keep the loonies on the path ...

Similar Threads

  1. Pass variable from a form to another form
    By dark1988 in forum Qt Programming
    Replies: 5
    Last Post: 8th February 2011, 18:19
  2. Replies: 5
    Last Post: 12th March 2010, 21:43
  3. Hiding a form and opening another form
    By anafor2004 in forum Newbie
    Replies: 1
    Last Post: 20th February 2008, 15:04
  4. Calling a new form from current form
    By webgenius in forum Qt Programming
    Replies: 7
    Last Post: 8th April 2007, 19:50
  5. Replies: 1
    Last Post: 28th July 2006, 14:10

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.