| ID | ... | Creation date | June 22, 2009 |
| Platform | S60 3rd Edition, FP1, FP2 S60 5th Edition | Tested on devices | Nokia 5800 XpressMusic |
| Category | Qt for Symbian | Subcategory |
| Keywords (APIs, classes, methods, functions): XQInstaller::install(), XQInstaller::remove(). |
This code snippets shows how to install/uninstall application silently. The XQInstaller can be used to silently install/uninstall the SISX without user intervention.
This snippet 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.
#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
symbian:LIBS += -lswinstcli \
-lcommdb \
-lapparc \
-lefsrv \
-lapgrfx
symbian:TARGET.CAPABILITY += TrustedUI
#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();
}
}
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();
}
}
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();
}
The code snippet is expected to install/uninstall helloworld application silently.
No related wiki articles found