我正在尝试运行一个程序,让它在 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
我正在关注文档
HOWTO: Start an external program from a Qt application
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";
}
它不编译,我得到错误。本教程正确吗?
查看错误
../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
我不认为发布所有代码是正确的礼仪,所以我只是发布了错误和我遇到问题的按钮代码。我应该发布所有代码吗?
如果这有帮助,这是 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();
}