我想用QProcess
從GUI啓動mysql。我試過以下內容:QProcess GUI不凍結
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());
但是,有一個很大的問題,因爲它在Qt文檔中提到,它會凍結。 我該如何解決這個問題?許多人建議使用QThread
,但我不知道該怎麼做? 預先感謝!
恩,謝謝!另外,如何在mysql密碼或用戶帳戶輸入錯誤時提示警告消息框。連接readyReadStandardOutput()信號後,我發現這個問題會有問題。你能幫我嗎? – elgolondrino
@elgolondrino,我認爲這取決於'mysql'報告關於不正確的用戶名/密碼輸入:退出與錯誤代碼,打印出錯誤信息到標準輸出或標準錯誤? – vahancho