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 "ok" button closes whole program.
Qt 6.11 is out! See what's new in the release blog

QMessageBox "ok" button closes whole program.

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.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.
  • H Offline
    H Offline
    hoomz
    wrote on last edited by
    #1

    Hey guys i'm new to qt and I'm trying to display an error by opening up a new QMessage box when when a button is clicked and an input was wrong.

    Here's by code

    @void errorFunction()
    {
    if(/some code/)
    {

    }
    

    else
    {
    QMessageBox *msgBox== new QMessageBox();

    msgBox->setText("You didn't enter a number 1-5! Try again");

    msgBox->exec();
    }

    }@

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

      Hi,

      From where is errorFunction called ?

      Note that you have a memory leak here. Either delete msgBox after the call to exec or allocate it on the stack.

      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
      • H Offline
        H Offline
        hoomz
        wrote on last edited by
        #3

        Hi, errorFunction is called when I click a button. So I connected the button to this function like this:

        @connect(rateButton,SIGNAL(clicked()),this,SLOT(errorFunction()));
        @

        [quote author="SGaist" date="1417993095"]Hi,

        From where is errorFunction called ?

        Note that you have a memory leak here. Either delete msgBox after the call to exec or allocate it on the stack.[/quote]

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

          What should be executed after that slot is called ?

          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
          • D Offline
            D Offline
            DBoosalis
            wrote on last edited by
            #5

            And should that not be an assignment operator(=) instead of an equivalense test (==) operator

            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