Results 1 to 3 of 3

Thread: Using Variables From Dialog In MainWindow

  1. #1
    Join Date
    Oct 2012
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question Using Variables From Dialog In MainWindow

    Hello,

    I am pretty new to qt creator and I have a pretty simple problem that I am sure is easily solved:

    I have a MainWindow form and a Dialog form. In the Dialog form you select a pixmap from a file and it gets stored in a variable. But, how do I go about getting that variable in my MainWindow form so that I can display the pixmap there...?

    Sorry if this is a newbie question but you gotta start somewhere,
    Matt

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Using Variables From Dialog In MainWindow

    This is not really a Qt question: it's a standard C++ question with standard C++ answers.
    • Provide your dialog class with a public getter function that gets the file name so the main window code can pull the value out of the dialog (like QFileDialog::selectedFiles()).
    • Provide your dialog class with a single function that displays the dialog and returns the selected file name (like QFileDialog::getOpenFileName() and friends).
    • Provide your main window class with a public setter function so that the dialog can push the file name back to the main window (through a pointer or reference to the main window).


    For a Qt flavoured response you could emit a signal when a file is selected and connect that to a slot in the main window object. This is just a special case of the third option.

    Which you choose depends on the exact requirements of the your program.

  3. #3
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using Variables From Dialog In MainWindow

    very similar question answered elsewhere
    http://www.qtforum.org/article/38095...m-dialogs.html
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. dialog button connected into mainwindow
    By ditsikts in forum Newbie
    Replies: 1
    Last Post: 26th October 2011, 23:17
  2. How to call a dialog from a mainwindow
    By luiz4um in forum Qt Programming
    Replies: 26
    Last Post: 29th June 2010, 10:41
  3. Open Dialog from MainWindow.
    By halvors in forum Qt Programming
    Replies: 8
    Last Post: 1st April 2010, 01:09
  4. Communication between MainWindow and a dialog
    By Backslash in forum Newbie
    Replies: 9
    Last Post: 3rd August 2007, 04:27
  5. Replies: 2
    Last Post: 23rd May 2007, 03:51

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.