Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1027141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:11:42+00:00 2026-05-16T12:11:42+00:00

I have a Qt main window that will pop up a dialog box that

  • 0

I have a Qt main window that will pop up a dialog box that has an OK and Cancel button. This dialog has a simple spinner that asks a user for a number that should be returned to the main window when OK or Cancel is pressed (for cancel, it will just send back -1).

I thought about using code in a signal in mainWindow.cpp like so:

void mainWindow::slot_openNumberDlg(){
    // Create a new dialog
    numberDlg dlg( this );

    // Show it and wait for Ok or Cancel
    if( dlg.exec() == QDialog::Accepted ){
        return;
    }
}

But how would I return the value of the spinner in the dialog back to main window if it is destroyed when the button is pressed?

I also thought about an alternative solution where I would initialize the dialog in mainWindow’s constructor, but it isn’t shown until a signal activated a slot in mainWindow.cpp like so:

// Create as pointer in main.h:
numberDlg *dlg;

// Initialize pointer and setup listener in constructor (main.cpp):
mainWindow::mainWindow(){
    dlg = new numberDlg();
    QObject::connect( dlg, SIGNAL( sig_retVal(int) ), ui->widget, SLOT( slot_showNum(int) ) );
}

// Make a function to handle show/close:
void mainWindow::slot_numberOpenClose(bool trigger){
    if(trigger){
        dlg->show();
    } else {
    dlg->close();
    }
}

The above code would be able to send the number from the dialog’s spinner to mainWindow using a signal/slot, but it won’t lock out mainWindow. I do not want the user to continue using mainWindow until the dialog has been accepted or rejected.

Any ideas on how I can lock the main window and send a number back to main on dialog close?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T12:11:42+00:00Added an answer on May 16, 2026 at 12:11 pm

    What you should do is create a function in your dialog class that returns the value you want, and use it like so from your main window:

    void mainWindow::slot_openNumberDlg(){
        // Create a new dialog
        numberDlg dlg( this );
    
        // Show it and wait for Ok or Cancel
        if( dlg.exec() == QDialog::Accepted ){
            m_theValue = dlg.myValue(); // <--
            return;
        }
    } // dlg goes out of scope
    

    dlg won’t be destroyed until it goes out of scope where I placed the comment, so your method will work fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PyGTK GUI that has a gtk.Table. Pressing one button will generate
I have a main canvas 'blackboard' in a panel, this canvas has itself several
In my current program I have a main window and a secondary window that
I have a main window (#1) on my webpage from which I open a
I have an Air application with a main window. I would like to have
I'm working on a project that has a glade GUI. I need the main
I have below a code that will plot a sphere, it's proportions are defined
I have this strange problem where my client will hang when it calls a
I have a text box in wxpython (see below) that stores the name of
I have a small application to convert several file formats, with a main windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.