我正在尝试运行一个程序,让它在ubuntu 12.04中启动一个外部linux程序.当它被输入终端窗口时该命令有效,但是当它被放入QT 4.8中点击的按钮对象时,我似乎无法使它工作.
这是在终端窗口中输入时有效的代码.(它访问网络摄像头并使用叠加层).我想要做的是每当按下一个按钮时,它将拍摄网络摄像头并使用日期和时间作为文件名保存图像)
gst-launch-0.10 v4l2src ! video/x-raw-yuv, width=640, height=480 ! timeoverlay halignment=right valignment=bottom shaded-background=true ! clockoverlay halignment=left valignment=bottom text="M/D/Y:" shaded-background=true time-format="%m/%d/%Y %H:%M:%S" ! autovideosink
Run Code Online (Sandbox Code Playgroud)
我正在关注文件
HOWTO:从Qt应用程序启动外部程序
http://www.qtforum.org/article/3079/howto-start-an-external-program-from-a-qt-application.html
但是当我在QT中将代码添加到按钮时
void runprg2::on_pushButton_clicked()
{
commandAndParameters<<"gst-launch-0.10 v4l2src ! video/x-raw-yuv, width=640, height=480 ! timeoverlay halignment=right valignment=bottom shaded-background=true ! clockoverlay halignment=left valignment=bottom text="M/D/Y:" shaded-background=true time-format="%m/%d/%Y %H:%M:%S" ! autovideosink";
}
Run Code Online (Sandbox Code Playgroud)
它不编译,我得到错误.这个教程是否正确?
请参阅错误
../test3/main.cpp: In function 'int main(int, char**)':
../test3/main.cpp:23:26: error: expected primary-expression before '<<' token
../test3/main.cpp:28:48: error: no matching function for call to 'QProcess::QProcess(QStringList&)'
../test3/main.cpp:28:48: note: candidates are:
/usr/include/qt4/QtCore/qprocess.h:228:5: note: QProcess::QProcess(const QProcess&)
/usr/include/qt4/QtCore/qprocess.h:228:5: note: no known conversion for argument 1 from 'QStringList' to 'const QProcess&'
/usr/include/qt4/QtCore/qprocess.h:133:14: note: QProcess::QProcess(QObject*)
/usr/include/qt4/QtCore/qprocess.h:133:14: note: no known conversion for argument 1 from 'QStringList' to 'QObject*'
../test3/main.cpp:31:25: error: no matching function for call to 'QProcess::start()'
../test3/main.cpp:31:25: note: candidates are:
/usr/include/qt4/QtCore/qprocess.h:136:10: note: void QProcess::start(const QString&, const QStringList&, QIODevice::OpenMode)
/usr/include/qt4/QtCore/qprocess.h:136:10: note: candidate expects 3 arguments, 0 provided
/usr/include/qt4/QtCore/qprocess.h:137:10: note: void QProcess::start(const QString&, QIODevice::OpenMode)
/usr/include/qt4/QtCore/qprocess.h:137:10: note: candidate expects 2 arguments, 0 provided
make: *** [main.o] Error 1
Run Code Online (Sandbox Code Playgroud)
我不认为发布所有代码是正确的礼仪所以我只是发布错误和我遇到问题的按钮代码.我应该发布所有代码吗?
如果这有帮助,这是main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
#include <qapplication.h>
#include <qprocess.h>
#include <qstringlist.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
// Set up the command line which starts the external program as QStringList.
QStringList commandAndParameters;
/* Fill in the following things:
* - Name of program to execute.
* - Every option needed by the program.
* Attention: be aware of any strange options you pass to the program, e.g.
* IP addresses. Quoting these options will usually help.
*/
// commandAndParameters<<"konqueror"
<<"file:/home/thomas";
/* Create a QProcess instance. It does not matter if it is created on the stack or
* on the heap. - Ahem, I tested it on Linux only. :-)
*/
QProcess myProcess(commandAndParameters);
// Start the QProcess instance.
myProcess.start();
/* O.k., everything is fine now, leave the Qt application. The external program
* will continue running.
*/
return 0;
return a.exec();
}
Run Code Online (Sandbox Code Playgroud)
一些东西:
使用指针创建进程:
QProcess*process = new QProcess(命令,参数);
使用a QString作为命令,使用a 作为QStringList参数:
QString command ="gst-launch-0.10"; QStringList参数; parameters <<"param1"<<"param2"<<"param3";
启动正常或分离的过程:
流程 - >开始(); 流程 - > startDetached();
| 归档时间: |
|
| 查看次数: |
10217 次 |
| 最近记录: |