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. QMessageBox Non-Modal using signal/slot

QMessageBox Non-Modal using signal/slot

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 915 Views
  • 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.
  • L Offline
    L Offline
    leinad
    wrote on last edited by
    #1

    Hi,

    I looked online and couldn't find an answer although I'm sure there must be a solution somewhere.

    I have a QMessageBox which is currently modal and uses exec() to display the text. The method that uses QMessageBox is located in a slot. If I set the modal flag to false I need to use show() instead of exec() but as we know if I use show(), the life of the messageBox is in scope for as long we are in the slot and then the box disappears., so essentially I see a flashing box when the slot gets called. I only have one button (OK) in the messageBox to close it.

    Can someone please explain how I can continue to use the slot (requirement) when calling QMessageBox and still make it non-modal?

    Thanks in advance!

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      Just allocate it on the heap...

      QMessageBox* msgBox= new QMessageBox(QMessageBox::Information,tr("Title"),tr("Text"),QMessageBox::Ok,this);
      msgBox->setAttribute(Qt::WA_DeleteOnClose);
      msgBox->show();
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      1
      • L Offline
        L Offline
        leinad
        wrote on last edited by
        #3

        @VRonin said in QMessageBox Non-Modal using signal/slot:

        QMessageBox* msgBox= new QMessageBox(QMessageBox::Information,tr("Title"),tr("Text"),QMessageBox::Ok,this);
        msgBox->setAttribute(Qt::WA_DeleteOnClose);
        msgBox->show();

        Hmm, still modal. What seems to work is if I make msgBox a private variable in the class but would prefer if we can use your method if I can get it to work.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          leinad
          wrote on last edited by
          #4

          Got it to work, forgo to add
          msgBox->setModal(false);

          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