你好,请问在Qt下想调用一个脚本文件应该怎么办呢?

the_passenger 2017-04-17 11:47:20
刚接触Qt,。我是想在Qt中调用自己写的shell脚本。enc1.sh和enc2.sh。而且是带参数调用哦,本来放在终端中应该是:
./enc1.sh xxx.txt xxx.txt 这种。
意思是对某个文件进行加密。然后,参数我是利用了LineEdit,从界面中传进来。
然后想请问,QProcess类中的start函数可以实现这个功能吗?我编写了如下的代码,但是不好使!

void Encrypt::on_encBtn_clicked()
{
QString s1 = ui->fileLineEdit->text();
QString s2 = ui->pswdLineEdit->text();
QString s3 = ui->xLineEdit->text();
QString command;
QString command1;
QString command2;
command.append("./enc1.sh");
command.append(" ");
command.append(s1);
command.append(" ");
command.append(s2);
command1.append("./enc2.sh");
command1.append(" ");
command1.append(s1);
command1.append(" ");
command1.append(s2);
command2.append("./cpabe-enc pub_key ");
command2.append(s2);
command2.append(" ");
command2.append(s3);
QProcess p(0);
p.setWorkingDirectory("/Users/czy/Desktop/cpabe");
p.start(command);
p.waitForFinished();
p.start(command2);
p.waitForFinished();
p.start(command1);
p.waitForFinished();
}


...全文
534 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
得不出结果可以写个槽函数关联QProcess的void error(QProcess::ProcessError error) 信号看看是不是执行过程中发生了其他错误。建议查看一下qt助手的QProcess类,应该有你想要的相关资料。
astro_lee 2017-04-19
  • 打赏
  • 举报
回复
我觉得你应该调用QProcess::error和QIODevice::errorString获取错误信息看看
caiwei_cs 2017-04-18
  • 打赏
  • 举报
回复
掉脚本和调用其他程序是一样的。没区别。
the_passenger 2017-04-18
  • 打赏
  • 举报
回复
改了改了..但是依然不对!跑不出结果..


void Encrypt::on_encBtn_clicked()
{
    QString s1 = ui->fileLineEdit->text();
    QString s2 = ui->pswdLineEdit->text();
    QString s3 = ui->xLineEdit->text();
    QString command1 = "./enc1.sh";
    QString command2 = "./cpabe-enc";
    QString command3 = "./enc2.sh";
    QStringList argu1;
    QStringList argu2;
    QStringList argu3;
    argu1<<s1<<s2;
    argu2<<"pub_key"<<s2<<s3;
    argu3<<s1<<s2;

    QProcess p(0);
    p.setWorkingDirectory("/Users/czy/Desktop/cpabe");
    p.start(command1,argu1);
    p.waitForFinished();
    p.start(command2,argu2);
    p.waitForFinished();
    p.start(command3,argu3);
    p.waitForFinished();
}

毛的。有没有函数说明手册啊..这玩意也不报错,我也不知道哪里除了问题
the_passenger 2017-04-18
  • 打赏
  • 举报
回复
好的好的..试一下先
我一板砖下去 2017-04-17
  • 打赏
  • 举报
回复
没调过shell,调过exe,不过看你代码p.start()里面,可执行文件和参数要分开, QString program = "./ccc.exe" ; QStringList arguments ; arguments <<"1.txt"; Process->start( program ,arguments ); 类似这样

16,216

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧