PDA

View Full Version : Using Variables From Dialog In MainWindow



steadi
7th October 2012, 13:38
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

ChrisW67
7th October 2012, 22:24
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.

amleto
7th October 2012, 23:18
very similar question answered elsewhere
http://www.qtforum.org/article/38095/how-mainwindow-reads-data-from-dialogs.html