×
Namespaces

Variants
Actions

如何让S60 Qt启动一个程序

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

兼容于
平台:
Symbian

文章
翻译:
hoolee
最后由 hamishwillee 在 11 Oct 2012 编辑


Contents

简介

下列代码示例演示了如何启动一个原生的S60 Qt Symbian程序

前言

头文件

ProcessHandler开始处理并监听状态

#include <QObject>
#include <QProcess>
 
class ProcessHandler : public QObject
{
Q_OBJECT
 
public:
ProcessHandler(QObject *parent = 0);
~ProcessHandler();
 
public:
void StartCameraApp();
 
public Q_SLOTS:
void stateChanged(QProcess::ProcessState state);
void error(QProcess::ProcessError error);
 
private:
QProcess* process;
};


源文件

生成QProcess开始监听进程状态变化

ProcessHandler::ProcessHandler(QObject *parent)
: QObject(parent)
{
process = new QProcess(this);
QObject::connect(process, SIGNAL(stateChanged(QProcess::ProcessState)),
this, SLOT(stateChanged(QProcess::ProcessState)));
}

类描述:

ProcessHandler::~ProcessHandler()
{
if (process->state() != QProcess::NotRunning)
{
// Close process if it is running
process->close();
}
}


启动Symbian原生的程序Cameraapp.exe:

void ProcessHandler::StartCameraApp()
{
QString program = "Cameraapp.exe";
process->start(program);
}

QProcess将错误信号发送到slot中

void ProcessHandler::error(QProcess::ProcessError error)
{
switch (error)
{
case QProcess::FailedToStart:
case QProcess::Crashed:
case QProcess::Timedout:
case QProcess::ReadError:
case QProcess::WriteError:
case QProcess::UnknownError:
{
// TODO: Handle error
break;
}
default:
{
break;
}
};
}

QProcess通知进程状态的改变到stateChanged中.

void ProcessHandler::stateChanged(QProcess::ProcessState state)
{
switch (state)
{
case QProcess::NotRunning:
case QProcess::Starting:
case QProcess::Running:
{
// TODO: do what you want with
// different states
break;
}
default:
{
break;
}
};
}


后记

这样S60 Qt程序即可启动摄像头程序


]

This page was last modified on 11 October 2012, at 04:19.
169 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×