Billy Edson
Billy Edson

Reputation: 33

How to use the ui class when I create a qt application

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

Upvotes: 0

Views: 105

Answers (1)

laurent
laurent

Reputation: 90736

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.

Upvotes: 1

Related Questions