×
Namespaces

Variants
Actions
(Difference between revisions)

Launching a native application from Qt

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
hamishwillee (Talk | contribs)
m (Hamishwillee - Fix categories)
 
Line 1: Line 1:
[[Category:Qt]][[Category:UI]][[Category:Code Snippet]][[Category:Code Snippet]]
+
[[Category:Qt]][[Category:Code Snippet]][[Category:MeeGo Harmattan]][[Category:Symbian]][[Category:General Programming]]
 +
{{Abstract|This code snippet shows how to launch a native application from Qt. The example has been tested launching the Symbian camera application on the Symbian platform, but the code should work generically.}}
 +
 
 
{{ArticleMetaData <!-- v1.2 -->
 
{{ArticleMetaData <!-- v1.2 -->
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
Line 24: Line 26:
 
|id= CS001354
 
|id= CS001354
 
}}
 
}}
 
==Overview==
 
 
This code snippet shows how to launch a native application from Qt. The example has been tested launching the Symbian camera application on the Symbian platform, but the code should work generically.
 
  
 
==Header==
 
==Header==
Line 139: Line 137:
  
 
==Postconditions==
 
==Postconditions==
The Symbian native camera is started.[[Category:MeeGo Harmattan]] [[Category:Symbian]]
+
The Symbian native camera is started.  
 
<!-- Translation --> [[zh-hans:如何让S60 Qt启动一个程序]]
 
<!-- Translation --> [[zh-hans:如何让S60 Qt启动一个程序]]

Latest revision as of 09:06, 17 October 2012

This code snippet shows how to launch a native application from Qt. The example has been tested launching the Symbian camera application on the Symbian platform, but the code should work generically.

Article Metadata
Tested with
SDK: Qt SDK
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition
Symbian
Article
Keywords: QProcess
Created: tepaa (29 Apr 2009)
Last edited: hamishwillee (17 Oct 2012)

[edit] Header

The ProcessHandler starts the process and listens for its states.

#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;
};


[edit] Source

Create QProcess and start listening for process state changes.

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

Class descruction:

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


Start the Symbian native camera Cameraapp.exe:

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

QProcess signals the error to the error 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 signals the process state changes to the stateChanged slot.

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;
}
};
}


[edit] Postconditions

The Symbian native camera is started.

This page was last modified on 17 October 2012, at 09:06.
68 page views in the last 30 days.