×
Namespaces

Variants
Actions

Silent installation/uninstallation of application in Qt

From Nokia Developer Wiki
Jump to: navigation, search


Article Metadata
Code ExampleTested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition
Symbian
Article
Keywords: XQInstaller.
Created: savaj (22 Jun 2009)
Last edited: hamishwillee (11 Oct 2012)

Contents

Overview

The Installer API can be used to install and uninstall applications without notifying the user through the standard installation dialogs. So you can use this API silently to install applications or you can create for example your own installation user interface.

This code snippet shows how to install/uninstall a Symbian application silently (without user intervention).

This snippet uses XQInstaller and requires TrustedUI capabilities. Self-signing is not possible because a [[Developer Certificate] is needed.

Note: This snippet can not work on emulator, so need to test it on real device.

Preconditions

Headers file

#ifndef SILENTINSTALLUNINSTALL_H
#define SILENTINSTALLUNINSTALL_H
 
#include <QtGui/QMainWindow>
#include "ui_SilentInstallUninstall.h"
#include "xqinstaller.h"
 
class SilentInstallUninstall : public QMainWindow
{
Q_OBJECT
 
public:
SilentInstallUninstall(QWidget *parent = 0);
~SilentInstallUninstall();
 
public Q_SLOTS:
//slots to receive action of menu trigger.
void installHelloWorldAction();
void uninstallHelloWorldAction();
//slots to receive signal from XQInstaller.
void installationComplete();
void installationError();
void uninstallationComplete();
void uninstallationError();
 
public:
//new functios
void SilentInstall();
void SilentUninstall();
void createMyMenu();
 
private:
Ui::SilentInstallUninstallClass ui;
 
QAction* menu_installHelloWorldAction;
QAction* menu_uninstallHelloWorldAction;
QAction* menu_exitAction;
 
XQInstaller *installer;
bool result;
};
 
#endif // SILENTINSTALLUNINSTALL_H

.pro file

symbian:LIBS += -lswinstcli \
-lcommdb \
-lapparc \
-lefsrv \
-lapgrfx
symbian:TARGET.CAPABILITY += TrustedUI

Source

#include "SilentInstallUninstall.h"
#include <QMessageBox>
#include <QDir>
 
SilentInstallUninstall::~SilentInstallUninstall()
{
 
}
 
SilentInstallUninstall::SilentInstallUninstall(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
setWindowTitle("SilentInstallUninstall");
createMyMenu();
 
// Create the installer class
installer = new XQInstaller(this);
 
}


 
void SilentInstallUninstall::SilentUninstall()
{
 
connect(installer,SIGNAL(applicationRemoved()),this,SLOT(uninstallComplete()));
connect(installer,SIGNAL(error()),this,SLOT(uninstallError()));
 
/* ED8788DC is UID of helloworld
* convert UID from hex to decimal
*/

QString str = "0xED8788DC";
bool ok;
uint appId = str.toUInt(&ok,16);
 
/* Uninstall the application with the given UID
* Or result = installer->remove(3985082588);
*/

result = installer->remove(appId);
 
if (!result)
{
uninstallationError();
}
 
}

In SilentUninstall() function we uninstall an application without informing the user.Each application has a unique identifier, so this is how you specify which application to uninstall. After the process is completed, either an applicationRemoved() or error() signal is emitted depending on whether the uninstalling was successful or not.


void SilentInstallUninstall::SilentInstall()
{
// Connect to the applicationInstalled() signal
connect(installer,SIGNAL(applicationInstalled()),this,SLOT(installationComplete()));
connect(installer,SIGNAL(error()),this,SLOT(installationError()));
 
// Install HelloWorld.SISX from private path
QString fileName = QDir::cleanPath(QDir::currentPath() + QLatin1Char('/') + "HelloWorld.SISX");
result = installer->install(fileName.replace("/","\\"));
if (!result)
{
installationError();
}
 
}

In SilentInstall() function we install an application from an installation file. On the Symbian platform, the installation package is referred to as a SIS file and has a .SISX extension. After installation is completed, either an applicationInstalled() or error() signal is emitted depending on whether the installation was successful or not . We catch the value in result and process it for error checking.

 
void SilentInstallUninstall::createMyMenu()
{
menu_installHelloWorldAction = new QAction(tr("Install HelloWorld"), this);
menuBar()->addAction(menu_installHelloWorldAction);
connect(menu_installHelloWorldAction, SIGNAL(triggered()), this, SLOT(installHelloWorldAction()));
 
menu_uninstallHelloWorldAction = new QAction(tr("Uninstall HelloWorld"), this);
menuBar()->addAction(menu_uninstallHelloWorldAction);
connect(menu_uninstallHelloWorldAction, SIGNAL(triggered()), this, SLOT(uninstallHelloWorldAction()));
 
menu_exitAction = new QAction(tr("Exit"), this);
menuBar()->addAction(menu_exitAction);
connect(menu_exitAction, SIGNAL(triggered()), this, SLOT(close()));
}
 
void SilentInstallUninstall::installHelloWorldAction()
{
SilentInstall();
}
 
void SilentInstallUninstall::uninstallHelloWorldAction()
{
SilentUninstall();
}
 
void SilentInstallUninstall::installationComplete()
{
QMessageBox::information(0,"Congrets!!!", "Application is installed sucessfully");
}
 
void SilentInstallUninstall::installationError()
{
QMessageBox msgBox;
msgBox.setText("Error in installation.");
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
 
switch (installer->error())
{
case XQInstaller::OutOfMemoryError:
{
msgBox.setInformativeText("Not enough memory");
}
break;
case XQInstaller::AlreadyInUseError:
{
msgBox.setInformativeText("Installer is already in use");
}
break;
case XQInstaller::UserCancelError:
{
msgBox.setInformativeText("Installer cancelled by the user.");
}
break;
case XQInstaller::PackageNotSupportedError:
{
msgBox.setInformativeText("Package not supported");
}
break;
case XQInstaller::SecurityFailureError:
{
msgBox.setInformativeText("Security failure");
}
break;
case XQInstaller::MissingDependencyError:
{
msgBox.setInformativeText("Missing dependency");
}
break;
case XQInstaller::NoRightsError:
{
msgBox.setInformativeText("No rights ");
}
break;
case XQInstaller::BusyError:
{
msgBox.setInformativeText("Installer is busy");
}
break;
case XQInstaller::AccessDeniedError:
{
msgBox.setInformativeText(" Access denied");
}
break;
case XQInstaller::UpgradeError:
{
msgBox.setInformativeText(" Error while upgrading");
}
break;
case XQInstaller::UnknownError:
{
msgBox.setInformativeText("Unknown error.");
}
break;
 
default:
break;
}
 
msgBox.exec();
}

Postconditions

The code snippet is expected to install/uninstall helloworld application silently.

Code Example

  • The Code Example will show how to install/uninstall application silently. The application is tested on Nokia 5800 XpressMusic.


Related Links

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