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
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.
Re: Using Variables From Dialog In MainWindow