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 7820797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:26:00+00:00 2026-06-02T07:26:00+00:00

I am developing a project using Qt4 and I have run into a slight

  • 0

I am developing a project using Qt4 and I have run into a slight issue.
I am creating a modal window from the main window. I want this to disable the toolbar at the top.
I have a menu item that spawns the modal from the menu. What I want is that when the modal is spawned that menus is disabled. I have tried using the setEnabled(false) function but that doesn’t reset it.

Here is the code:

void Main_Screen::Create_ViPro()
{
   std::auto_ptr<ViPro_Dialog> modal(new ViPro_Dialog(this));
   modal->show();
   modal->exec();
}

So It is just a simple class that is triggered when a menu item is selected. I feel that the problem stems from the fact that i’m setting the parent to the main screen, however I don’t know how to create a modal without a parent(it doesn’t make sense to do that). Is there a way to disable the parents toolbar from the child? The only thing I have seen so far is _fileMenu->setEnabled(false);
That works as long as I don’t create the modal, but as soon as that is spawned, the menu works again. I’m totally lost.
Thanks in advance

Edit as Patrice

Here is the constructor

    Main_Screen::Main_Screen(QWidget* parent /*= NULL*/) 
                        : QMainWindow(parent),
                          _newProj(new QAction(tr("New &ViPro"), this)),
                          _fileMenu(menuBar()->addMenu(tr("&File")))
{    
  //create slot for creating a new project
  connect(_newProj.get(), SIGNAL(triggered()), this, SLOT(Create_ViPro()));
  _fileMenu->addAction(_newProj.get());
  //if i do this then setEnabled(false) works perfectly and i can't access the menu
  Create_ViPro()
}

So the function is signaled by triggering the newproject action. If i call the function directly from within the constructor it disables it as you stated patrice, however, if I have the function called via the trigger, it doesn’t disable it. Am I handling the signal / slot mechanism wrong? Thanks again.

Another example, if I make the function create_vipro() as below

void Main_Screen::Create_ViPro()
{
     _fileMenu->setEnabled(false);
}

The file menu isn’t disabled when I trigger the event, so it must have nothing to do with the modal itself, but instead how signals are handled.

  • 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-06-02T07:26:01+00:00Added an answer on June 2, 2026 at 7:26 am

    Since child is a modal dialog main screen can’t react to event. But you can disable the toolbar (or menubar) before creating the modal dialog and enable it as soon as you leave the exec function:

    void Main_Screen::Create_ViPro()
    {
       _fileMenu->setEnabled(false);
    
       std::auto_ptr<ViPro_Dialog> modal(new ViPro_Dialog(this));
       modal->show();
       modal->exec(); // Will stay here until you close the modal dialog
    
       _fileMenu->setEnabled(true);
    }
    

    if ViPro_Dialog is really a modal dialog it will works.

    Another thing, since ViPro_Dialog is modal you can declare it locally without using auto_ptr:

    void Main_Screen::Create_ViPro()
    {
       _fileMenu->setEnabled(false);
    
       ViPro_Dialog modal(this);
       modal.show();
       modal.exec(); // Will stay here until you close the modal dialog
    
       _fileMenu->setEnabled(true);
    }
    

    EDIT:

    I guess (I can’t test at work) that you can’t enable/disable menu when it is executing a QAction. Signal is calling slots sequentially so QAction is busy when you try to disable the menu.
    Try this:

    1. In Main Screen, create a slot with one boolean parameter that enable/disable menubar. Just call the setEnabled function
    2. In ViPro_Dialog, emit a signal with a boolean parameter (false at startup, true at validation)
    3. In Create_ViPro, once dialog created, connect the new signal with the slot, exec dialog and don’t forget to disconnect slot from signal:

    void Main_Screen::Create_ViPro()
    {
    ViPro_Dialog modal(this);

    // Connect signal/slot

    modal.show();
    modal.exec(); // Will stay here until you close the modal dialog

    // Disconnect signal/slot
    }

    This can achieve what you want

    EDIT2

    You are doing a mistake when using modal dialog. There’s a conflict between show() and exec(). When you are displaying modal dialog you don’t need to disable other windows: it’s automatically done by modal status of the dialog. There are many modal depth: http://qt-project.org/doc/qt-4.8/qt.html#WindowModality-enum. So your code should be:

    void Main_Screen::Create_ViPro()
    {
       ViPro_Dialog modal(this);
    
       // modal.setWindowModality(Qt::WindowModal); // Uncomment this line if you want to only disable parent
    
       modal.exec();
    }
    

    Read this for more detail: http://qt-project.org/doc/qt-4.8/QDialog.html#details.

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

Sidebar

Related Questions

I am developing project using Spring , Struts2 & Hibernate . Now I want
I am using C# and developing a winform application. I have a project class
I am developing a website using MVC 3, I have a web setup project
I'm developing a fun little project using Foursquare API. In this project, I have
I am currently developing my project using Spring, Sutruts2 & Hibernate. Now i want
im now developing a project using winpcap..as i have known packets being sniffed are
I'm developing one web application project using java for education industry.In this Admin have
I have recently joined a new developing project building a thick client application using
I'm developing a project using PostGIS to hold spatial data where I have records
I'm developing a setup project using WiX , and I have the following problem.

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.