0

i have created a qt GUI to do some check out task and this show the results in labels. I use QT creator and this creates the header and mainwindow.cpp program. So my problem is that I have declared more methods into the header in order to do some task and with the results update a label but I have the problem that I use while loop and my GUI never starts. I have tried to run in a sequential way (without the loop) and this works but only calls the las function and the program doesn't follow the sequence (for example trying to do ping to server).

Below is a similar mianwindow.cpp program that I have,

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
while(1)
{
    ping2server()
    if(ping2server>0)
            ui->label->setText("The server is alive");
    else
            break;

}
/*the server is dead connecting to other one*/
.
.
//and so on

}

MainWindow::~MainWindow()
{
delete ui;
}

int MainWindow::png2server()
{

}
int MainWindow::conn2server()
{
}

Any ideas please let me know. I'm really new in this.

Thank you

1 Answer 1

1

You are freezing the whole application when you do a loop like that. Instead, you should use a QTimer and update the label using the timeout() signal.

Sign up to request clarification or add additional context in comments.

1 Comment

ok I did but the problem is that I'm using 2 timers and when I use them only one of them is updated and it's the last one. The GUI doesn't show the status of the first timer. why??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.