elgolondrino
elgolondrino

Reputation: 665

QProcess with GUI not freezing

I would like to launch mysql from GUI using QProcess. I've tried the following:

QStringList arguments;
arguments << QString("-u%1").arg("myaccount")<<  QString("-p%2").arg("password");

QProcess *mysql = new QProcess;
mysql->setReadChannelMode(QProcess::ForwardedChannels);
mysql->execute("mysql", arguments);

if(mysql->waitForReadyRead(-1))
    qDebug(mysql->readAllStandardOutput());

But, there is big problem as it's mentioned in Qt Documentation, it's gonna freeze. How can I solve this? Many advised to use QThread but I don't have any idea how to do that? Thanks beforehand!

Upvotes: 0

Views: 1141

Answers (2)

vahancho
vahancho

Reputation: 21220

The problem is that you call the QProcess::execute() function and it waits until the process is finished. If you need to avoid freezing you can use readyReadStandardOutput() signal and do the following:

[..]
connect(mysql, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput()));
mysql->start("mysql", arguments);
if (!mysql->waitForStarted()) {
    // report error
}

Upvotes: 1

Jessica
Jessica

Reputation: 715

This link may help you: QProcess fails to execute external executable

Calling MySQL : c:\mysql\mysql.exe -u MYUSERNAME -pMYPassword

There is no space between -p and password. Set MySQL Path.

Upvotes: 0

Related Questions