Qt newbie here :)。 我目前在Qt中使用popen
函數執行一個bash腳本,將輸出重定向到我的應用程序中的textBrowser。當我將腳本作爲資源添加到我的項目中時,它似乎不再執行?我使用:/myScript.sh
語法,然後嘗試將我的參數添加爲QStrings。 任何意見將不勝感激!運行帶參數的Bash腳本作爲Qt資源
FILE *in;
char buff[512];
QString args = ":/myScript.sh" + <arguments>;
QByteArray ba = args.toLatin1();
char *temp = ba.data();
if(!(in = popen(temp , "r")))
{
exit(1);
}
while(fgets(buff, sizeof(buff), in)!=NULL)
{
ui->txtConsole->append(buff);
}
ui->progressBar->setValue(50); pclose(in);
我不認爲這會起作用,但我不能確定沒有看到您的代碼。你可以分享你用來生成popen調用,':/ myScript.sh'和QString參數的代碼嗎? – selbie
'FILE * in; char buff [512]; QString args =「:/myScript.sh」+; QByteArray ba = args.toLatin1(); char * temp = ba.data();如果(!(in = popen(temp,「r」))){ exit(1); (fgets(buff,sizeof(buff),in)!= NULL){0} { } ui-> txtConsole-> append(buff); } pclose(in);' –
Sphics
由於您顯然是在GUI程序中,您可能需要考慮使用'QProcess'而不是'popen()'異步運行程序 –