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


Qt Code:
  1. void Dialog_Configure::connectDB(){
  2.  
  3. // Disable all buttons
  4. ui->buttonOK->setEnabled(false);
  5. ui->buttonCancel->setEnabled(false);
  6. ui->buttonConnect->setEnabled(false);
  7.  
  8. //Grab credentials from QLineEdit
  9.  
  10. QString DB_IPAddress = ui->lineIPAddress->text();
  11. int DB_PortAddress = ui->linePort->text().toInt();
  12. QString DB_UserName = ui->lineUserName->text();
  13. QString DB_Password = ui->linePassword->text();
  14.  
  15. ui->textEditDBStatusLog->insertPlainText("Connecting...\n\n"); // Add text to QTextEdit informing user of the initilised connection
  16.  
  17. // Instantiate an instance of MySQL_DB class
  18.  
  19. MySQL_DB connectionTest;
  20.  
  21. // Call connectionTest method of the MySQL_DB Class returning QString status
  22.  
  23. QString connectionStatus = connectionTest.connectionTest(DB_IPAddress, DB_PortAddress, DB_UserName, DB_Password);
  24.  
  25.  
  26. // Add SQL connection result into QTextEdit
  27.  
  28. ui->textEditDBStatusLog->insertPlainText(connectionStatus);
  29.  
  30.  
  31. }
To copy to clipboard, switch view to plain text mode