PDA

View Full Version : Execution order



Ishtar
26th April 2010, 17:34
Dear All

I have written a small class called MYSQL_DB which deals with all the steps required for QMYSQL (QtSql) with the database parameters being passed from another class. The following function should disable all QPushButton's, print a line to QTextEdit telling the user that the database connection routine is running and then instantiate the MYSQL_DB class and call one of its methods.

All this code works exactly as designed but with one major problem. The code at lines 4,5,6 and the QTextEdit->insertPlainText at line 15 does not run until the MYSQL_DB class has completed.

I cannot understand why this should be. Cam anybody help me with this dilemma?

Many thanks
Ishtar




void Dialog_Configure::connectDB(){

// Disable all buttons
ui->buttonOK->setEnabled(false);
ui->buttonCancel->setEnabled(false);
ui->buttonConnect->setEnabled(false);

//Grab credentials from QLineEdit

QString DB_IPAddress = ui->lineIPAddress->text();
int DB_PortAddress = ui->linePort->text().toInt();
QString DB_UserName = ui->lineUserName->text();
QString DB_Password = ui->linePassword->text();

ui->textEditDBStatusLog->insertPlainText("Connecting...\n\n"); // Add text to QTextEdit informing user of the initilised connection

// Instantiate an instance of MySQL_DB class

MySQL_DB connectionTest;

// Call connectionTest method of the MySQL_DB Class returning QString status

QString connectionStatus = connectionTest.connectionTest(DB_IPAddress, DB_PortAddress, DB_UserName, DB_Password);


// Add SQL connection result into QTextEdit

ui->textEditDBStatusLog->insertPlainText(connectionStatus);


}

Kumosan
26th April 2010, 18:55
Hard to believe. Your lines 4 - 15 are executed long before 19. But you use designer created classes and I don't have too much experience with those. Does not make too much sense, but I'd try to add a 'processEvents' before line 19.

Ishtar
26th April 2010, 20:36
Hi Kumosan

Many thanks for your help. Using the following fixed my problem. :)




qApp->processEvents();



Once again, thank you.

Ishtar