简体   繁体   中英

Qt 5.6 - Return 2 ints from a custom QDialog

My problem is: I have subclassed QDialog to get a dialog box that has 2 spinboxes, an ok and a cancel button. This new class is named MapCharacteristicsInputDialog.

Now, when I click a button on my main window, I'd like a dialog of this class to pop out, and then get the values from the spinboxes when it's closed using the Ok button. How can I do this ?

Code that triggers the pop out of the dialog:

void MainWindow::on_newMapButton_clicked(){
    MapCharacteristicsInputDialog* dialog = new MapCharacteristicsInputDialog();
    dialog->exec();
}

For starters, you should check what the exec function returns.

Then the simple way is to have two access-function in your MapCharacteristicsInputDialog class to get the values of the spinner. once exec returns.

You can use signals to transmit the values of the spinboxes along with their titles, and then connect those signals to the slots of whatever object that will be requiring the data.

Read more here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM