Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. SetModal() does not work in QDialog
Forum Updated to NodeBB v4.3 + New Features

SetModal() does not work in QDialog

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 4.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Exotic_Devel
    wrote on last edited by
    #1

    For some reason the setModal method is not working for me. Below is a snippet of code that calls a QDialog.

    @QHash<QString, QVariant>* DataAccess::getSettings() // Private method
    {
    QHash<QString, QVariant> *parameters = new QHash<QString, QVariant>();

    Configconnec *confconnec; /GUI for get parameters of connection/

    QSettings connecsettings( QSettings::IniFormat, QSettings::SystemScope, "Freedom", "TecTracker");

    connecsettings.beginGroup("Connection");

    if(!connecsettings.contains("host"))    /*If connection settings not existis*/
    {
        confconnec =  new Configconnec();
        confconnec->exec&#40;true&#41;;   /*Get new connection settings*/
    }
    
    parameters->insert("host", connecsettings.value("host", "127.0.0.1"));
    parameters->insert("port", connecsettings.value("port", 5432));
    parameters->insert("database", connecsettings.value("database", "postgres"));
    parameters->insert("user", connecsettings.value("user", "postgres"));
    parameters->insert("passw", connecsettings.value("passw", "postgres"));
    

    connecsettings.endGroup();

    if(confconnec)
    delete confconnec;

    return parameters;
    }@

    exec() method of Confconnec

    @QDialog* Configconnec::exec(bool modal) // Show connection form
    {
    diagconnec->setModal(modal);
    diagconnec->show();
    return diagconnec;
    }@

    If diagconnec is not modal, the program don't stop in line:

    @ if(!connecsettings.contains("host")) /If connection settings not existis/
    {
    confconnec = new Configconnec();
    confconnec->exec(true); /DON'T STOP HERE/
    }
    @

    He leaves the IF and step through the code, and I do not want it. He should expect the user closes the Dialog to proceed.
    I get the desired effect by calling the exec(), but with setModal() and show() does not work.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      There's no reason for your dialog to stop your application there. In your custom exec you are calling show which purpose is exactly to show your dialog without blocking the event loop.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Exotic_Devel
        wrote on last edited by
        #3

        Strange, the "documentation":http://qt-project.org/doc/qt-5/qdialog.html#modal-prop says that if we define the modal property to true, the show() loads widget as modal. And I'm setting to true before calling show()

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          AFAIK, modal doesn't mean "blocking your application's event loop", it means that you are blocking the access to the widgets underneath. If you want to block your application's flow, call the original exec()

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • E Offline
            E Offline
            Exotic_Devel
            wrote on last edited by
            #5

            ok!

            exec() is the only option or is there some property that can be set?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              It's the only option, however take also a look at open, it's also not blocking but proposes an alternative architecture that's worth to think about.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved