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. How to close QMessagebox with command automatically?

How to close QMessagebox with command automatically?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.2k 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.
  • V Offline
    V Offline
    victor wang
    wrote on last edited by
    #1

    Hi All,
    I'm trying to close the Messagebox that I utilize it to inform users that what my system is doing.
    After the system has done the work then I will close the Messagebox.

    Here is the part of my code.

    void MainWindow::on_pushButtonPT_Lantest_clicked()
    {
        if(!LanTabClick)
        {
            LanTabClick=true;
            initPTLan();
            //QMessageBox::information(NULL,"information","Begin lan test",QMessageBox::Cancel);
            MsgBox->information(NULL,"information","Begin lan test",QMessageBox::Cancel);
            /*MsgBox.setText("Begin lan test");
            MsgBox.setIcon(QMessageBox::Information);
            MsgBox.setStandardButtons(QMessageBox::Cancel);
            MsgBox.exec();*/
        }
    }
    
    void MainWindow::Lanshow(QString speed)
    {
        qDebug()<<"forenex victor speed:"<<speed;
        QString check,eth1;
        eth0_destination="/sbin/route -n | /bin/grep 255 | /bin/grep eth0";
        qDebug("In Lanshow");
        if(!Lanpingperf->twoLAN)
        {
            qDebug("In Lanshow ,not twoLan");
            if(speed.indexOf("failed")!=-1 || speed=="" || speed.right(11)=="unreachable")
            {
                qDebug("speed failed");
                ui->lineEditPT_LANResult->setText("Failed");
                ui->pushButtonPT_LAN_ResultLight->setStyleSheet("QPushButton{background-color:red;}");
                test_result[12]=false;
                ui->textEditPT_LAN->setText("LAN is not working. Cannot ping 8.8.8.8!!!! ");
                LanTabClick=false;
            }
            else
            {
                qDebug("speed Pass");
                ui->lineEditPT_LANResult->setText("Pass");
                ui->pushButtonPT_LAN_ResultLight->setStyleSheet("QPushButton{background-color:green;}");
                test_result[12]=true;
                ui->textEditPT_LAN->setText("LAN speed = "+speed);
                LanTabClick=false;
            }
            MsgBox->close();
      }
    }
    

    I will enable the Messagebox in function on_pushButtonPT_Lantest_clicked then wanna close it in function Lanshow.
    However, the message box shows perfectly but cannot close it when running MsgBox->close().

    What did I miss?

    Thanks in Advanced!

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You're looking for something like a QProgressDialog but not for a QMessageBox which requires user interaction.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2

      • Login

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