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. Non-modal QMessageBox causing application to exit
Forum Updated to NodeBB v4.3 + New Features

Non-modal QMessageBox causing application to exit

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.8k 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.
  • M Offline
    M Offline
    mrhixxy
    wrote on last edited by
    #1

    I'm trying to display a non-modal QMessageBox inside a QUdpSocket readyRead() slot. This is in response to a particular message received via UDP. I'm creating the QMessageBox as follows:

    @ static std::unique_ptr<QMessageBox> msgBox;

        msgBox.reset(new QMessageBox());
        msgBox->setWindowTitle("Some title");
        msgBox->setText("Some question?");
        msgBox->setStandardButtons(QMessageBox::Ok|QMessageBox::Ignore);
        msgBox->setModal(false);
        msgBox->setWindowFlags(msgBox->windowFlags() | Qt::WindowStaysOnTopHint);
        msgBox->show();
        connect(msgBox.get(), SIGNAL(buttonClicked(QAbstractButton*)),
                this, SLOT(msgBoxClosed(QAbstractButton*)));
    

    @

    The msgBoxClosed() function is currently empty, but I intend to react to which button is clicked. Upon clicking either Ok or Ignore, the application exits most of the time. If it doesn't happen the first time, it certainly does the second.

    This works fine if I make the QMessageBox modal, but the application needs to continue processing events while it waits for a response.

    Any ideas?
    This is the first time I've used Qt, so the problem is probably obvious to you guys.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Code_ReaQtor
      wrote on last edited by
      #2

      Why do you need to create a unique_ptr?

      @ static std::unique_ptr<QMessageBox> msgBox;

          msgBox.reset(new QMessageBox());@
      

      Maybe you can just make it like this:

      @QMessageBox *msgBox = new QMessageBox();@

      Please visit my open-source projects at https://github.com/Code-ReaQtor.

      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