如何获取安装在Qt设备中的应用程序图标列表

如何获取安装在Qt设备中的应用程序图标列表,qt,symbian,qicon,Qt,Symbian,Qicon,我正在使用Qt应用程序,我想在其中创建一个QListWidget,其中包含设备上安装的所有应用程序的名称及其图标。 因此,我无法从本文中的代码中获取每个应用程序的所有应用程序名和UID。 但我也无法获得应用程序图标。我尝试了这两种方法,但在这里我遇到了一些问题,比如如何将CGulIcon转换为QIcon,以及如何将CApaMaskedBitmap转换为QIcon 我怎样才能做到这一点呢?好吧,关于图标的事情,看看这个:CGullIcon有一个函数,返回位图,一个CFbsBitmap。完成后,请看

我正在使用Qt应用程序,我想在其中创建一个QListWidget,其中包含设备上安装的所有应用程序的名称及其图标。 因此,我无法从本文中的代码中获取每个应用程序的所有应用程序名和UID。 但我也无法获得应用程序图标。我尝试了这两种方法,但在这里我遇到了一些问题,比如如何将CGulIcon转换为QIcon,以及如何将CApaMaskedBitmap转换为QIcon


我怎样才能做到这一点呢?

好吧,关于图标的事情,看看这个:CGullIcon有一个函数,返回位图,一个CFbsBitmap。完成后,请看以下内容:然后创建一个新的QIcon(QPixmap)(QPixmap=已转换的图标)。因此,最有可能的情况是,首先将其传递给CFbsBitmap,然后使用FromSymbnacfbSBitmap()的QPixmap

如果我没有错的话,CApaMaskedBitmap是CFbsBitmap的一个子类,所以它的工作原理应该是一样的


对于获取应用程序及其UID,请尝试查看以下内容:

对于图标,请查看以下内容:CGullIcon有一个返回位图的函数,一个CfBbitMap。完成后,请看以下内容:然后创建一个新的QIcon(QPixmap)(QPixmap=已转换的图标)。因此,最有可能的情况是,首先将其传递给CFbsBitmap,然后使用FromSymbnacfbSBitmap()的QPixmap

如果我没有错的话,CApaMaskedBitmap是CFbsBitmap的一个子类,所以它的工作原理应该是一样的


要获取应用程序及其UID,请尝试查看以下内容:

如果您无法获得解决方案或有任何疑问需要讨论

main.cpp

#include "GetInstalledApps.h"

#include <QtGui>
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    GetInstalledApps w;
    w.showMaximized();
    return a.exec();
}
#include "GetInstalledApps.h"
#include <QScrollArea>

GetInstalledApps::GetInstalledApps(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);
    setWindowTitle("GetAllInstalledApps");
    m_installer = new XQInstaller(this);
    GetApps();
    
}

void GetInstalledApps::GetApps()
{
    /* Get List of applications. 
     * type of m_applications is QMap<QString, uint>.
     * type of  m_installer is XQInstaller
     */
    m_applications = m_installer->applications();
    
    /* Get List of application names
     type of m_appNames is QList<QString> */
    m_appNames = m_applications.keys(); 
    
    /* Get List of application UID in decimal. 
    type of m_appUID is QList<uint> */
    m_appUID = m_applications.values(); 
    
    ui.listWidget->clear();
    for (int i = 0; i < m_appNames.count(); i++) 
    {
        QString str;
        /* convert UID from decimal to hex and then string. */
        str.setNum(m_appUID.at(i),16);
        /* append name and UID to string */     
        QString string(m_appNames.at(i)+"  UID:"+ str);
        /* append string to list widget to display on screen */
        ui.listWidget->addItem(string);
    }
    
    /* Let's make the UI scale so that we can scroll it. */
    QScrollArea* scrollArea = new QScrollArea;
    scrollArea->setWidget(ui.listWidget);
    scrollArea->setWidgetResizable(true);

    setCentralWidget(scrollArea);
}

GetInstalledApps::~GetInstalledApps()
{

}
#include "xqinstaller.h"
#include "xqinstaller_p.h"

/*!
    \class XQInstaller
    \brief The XQInstaller class is used to install sis-packages silently. 
    This extension can be used for example to install back-end applications.

    Example:
    \code
    XQInstaller *installer = new XQInstaller(this);
    QMap<QString, uint> applications = installer->applications();
    QListWidget *applicationList = new QListWidget(this);
    QList<QString> appNames = applications.keys();
    for (int i = 0; i < appNames.count(); i++) {
        applicationList->addItem(appNames.at(i));
    }   
    \endcode
*/

/*!
    Constructs a XQInstaller object with the given parent.
    \sa install(), remove()
*/
XQInstaller::XQInstaller(QObject *parent)
    : QObject(parent), d(new XQInstallerPrivate(this))
{
}

/*!
    Destroys the XQInstaller object.
*/
XQInstaller::~XQInstaller()
{
    delete d;
}

/*!
    Installs a sis package silently given as parameter.

    \param file Sis package
    \param drive Drive letter where the sis is installed to. Default value is 'C'.
    \return If false is returned, an error has occurred. Call error() to get a value of 
    XQInstaller::Error that indicates which error occurred
    \sa error()
*/  
bool XQInstaller::install(const QString& file, XQInstaller::Drive drive)
{
    return d->install(file, drive);
}

/*!
    Get list of installed applications
    If an empty QMap is returned, an error has possibly occurred. Call error() to get a value of 
    XQInstaller::Error that indicates which error occurred if any
    
    \return List of installed applications
    \sa error()
*/
QMap<QString, uint> XQInstaller::applications() const
{
    return d->applications();
}

/*!
    Removes application specified by the uid
   
    \param uid of the application
    \return True if removing was successfully started, otherwise false
    \sa error()
*/
bool XQInstaller::remove(uint uid)
{
    return d->remove(uid);
}

/*!
    \enum XQInstaller::Error

    This enum defines the possible errors for a XQInstaller object.
*/
/*! \var XQInstaller::Error XQInstaller::NoError
    No error occured.
*/
/*! \var XQInstaller::Error XQInstaller::OutOfMemoryError
    Not enough memory.
*/
/*! \var XQInstaller::Error XQInstaller::AlreadyInUseError
    Installer is already in used.
*/
/*! \var XQInstaller::Error XQInstaller::UserCancelError
    Installer cancelled by the user.
*/
/*! \var XQInstaller::Error XQInstaller::PackageNotSupportedError
    Package not supported
*/
/*! \var XQInstaller::Error XQInstaller::SecurityFailureError
    Security failure
*/
/*! \var XQInstaller::Error XQInstaller::MissingDependencyError
    Missing dependency
*/
/*! \var XQInstaller::Error XQInstaller::NoRightsError
    No rights
*/
/*! \var XQInstaller::Error XQInstaller::BusyError
    Installer is busy
*/
/*! \var XQInstaller::Error XQInstaller::AccessDeniedError
    Access denied
*/
/*! \var XQInstaller::Error XQInstaller::UpgradeError
    Error while upgrading
*/
/*! \var XQInstaller::Error XQInstaller::UnknownError
    Unknown error.
*/

/*!
    Returns the type of error that occurred if the latest function call failed; otherwise returns NoError
    \return Error code
*/
XQInstaller::Error XQInstaller::error() const
{
    return d->error();
}

/*!
    \fn void XQInstaller::applicationInstalled()

    This signal is emitted when the application has been installed.

    \sa install()
*/

/*!
    \fn void XQInstaller::error(XQInstaller::Error)

    This signal is emitted if error occured during the asynchronous operation

    \sa install()
*/

/*!
    \fn void XQInstaller::applicationRemoved()

    This signal is emitted when the application has been removed.

    \sa remove()
*/

// End of file
#include "xqinstaller.h"
#include "xqinstaller_p.h"
#include <f32file.h>
#include <apgcli.h>

XQInstallerPrivate::XQInstallerPrivate(XQInstaller *installer) 
    : CActive(EPriorityNormal), q(installer), iOptionsPckg(iOptions), 
      iUninstallOptionsPckg(iUninstallOptions), iLauncherConnected(false)
{
    CActiveScheduler::Add(this);  
}

XQInstallerPrivate::~XQInstallerPrivate()
{
    Cancel();
    if (iLauncherConnected) {
        iLauncher.Close();
    }
}

bool XQInstallerPrivate::install(const QString& file, XQInstaller::Drive drive)
{
    int asciiValue = 10;  // = 'A'
    TRAP(iError,
        if (!iLauncherConnected) {
            User::LeaveIfError(iLauncher.Connect());
            iLauncherConnected = true;
        }
        if (IsActive()) {
            User::Leave(KErrInUse);
        }
        
        iState = XQInstallerPrivate::EInstall;
        iOptions.iUpgrade = SwiUI::EPolicyAllowed;
        iOptions.iOCSP = SwiUI::EPolicyNotAllowed;
        iOptions.iDrive = TChar(asciiValue+drive);
        iOptions.iUntrusted = SwiUI::EPolicyAllowed; 
        iOptions.iCapabilities = SwiUI::EPolicyAllowed;  
        iOptions.iOptionalItems = SwiUI::EPolicyAllowed;  
        iOptions.iOverwrite = SwiUI::EPolicyAllowed; 
        TPtrC16 fileName(reinterpret_cast<const TUint16*>(file.utf16()));
        iFileName = fileName;
        iLauncher.SilentInstall(iStatus, iFileName, iOptionsPckg);
        SetActive();
    )
    return (iError == KErrNone);
}

bool XQInstallerPrivate::remove(uint uid)
{
    TRAP(iError,
        if (!iLauncherConnected) {
            User::LeaveIfError(iLauncher.Connect());
            iLauncherConnected = true;
        }
        if (IsActive()) {
            User::Leave(KErrInUse);
        }

        iState = XQInstallerPrivate::ERemove;
    
        iLauncher.SilentUninstall(iStatus,TUid::Uid(uid),
            iUninstallOptionsPckg, SwiUI::KSisxMimeType);
        SetActive();
    )
    return (iError == KErrNone);
}

QMap<QString, uint> XQInstallerPrivate::applications() const
{
    RApaLsSession lsSession;
    QMap<QString, uint> applications; 
      
    // Connect to application architecture server
    TRAP(iError,
        User::LeaveIfError(lsSession.Connect());
        CleanupClosePushL(lsSession);
        
        TApaAppInfo appInfo;
        lsSession.GetAllApps();  
        
        while (lsSession.GetNextApp(appInfo) == KErrNone) {
            TApaAppCapabilityBuf capability;
            User::LeaveIfError(lsSession.GetAppCapability(capability,
                appInfo.iUid));
            if (appInfo.iCaption.Length() > 0 && !capability().iAppIsHidden) {
                QString fullName = QString::fromUtf16(
                    appInfo.iCaption.Ptr(), appInfo.iCaption.Length());
                applications.insert(fullName, (TUint)appInfo.iUid.iUid);
            }
        }
        CleanupStack::PopAndDestroy(&lsSession);
    )
      
    return applications; 
}

void XQInstallerPrivate::DoCancel()
{
    if (iState == XQInstallerPrivate::EInstall) {
        iLauncher.CancelAsyncRequest(SwiUI::ERequestSilentInstall);
    } else if (iState == XQInstallerPrivate::ERemove) {
        iLauncher.CancelAsyncRequest(SwiUI::ERequestSilentUninstall);
    }
}
 
void XQInstallerPrivate::RunL()
{
    if (iStatus.Int() == KErrNone) {
        if (iState == XQInstallerPrivate::EInstall) {
            emit q->applicationInstalled();
        } else if (iState == XQInstallerPrivate::ERemove) {
            emit q->applicationRemoved();
        }
    } else {
        iError = iStatus.Int();
        emit q->error(error());
    }
}

XQInstaller::Error XQInstallerPrivate::error()
{
    switch (iError) {
    case KErrNone:
        return XQInstaller::NoError;
    case SwiUI::KSWInstErrInsufficientMemory:
    case KErrNoMemory:
        return XQInstaller::OutOfMemoryError;
    case SwiUI::KSWInstErrFileInUse:
    case KErrInUse:
        return XQInstaller::AlreadyInUseError;
    case SwiUI::KSWInstErrUserCancel:
        return XQInstaller::UserCancelError;  
    case SwiUI::KSWInstErrPackageNotSupported:
        return XQInstaller::PackageNotSupportedError; 
    case SwiUI::KSWInstErrSecurityFailure:
        return XQInstaller::SecurityFailureError; 
    case SwiUI::KSWInstErrMissingDependency:
        return XQInstaller::MissingDependencyError; 
    case SwiUI::KSWInstErrNoRights:
        return XQInstaller::NoRightsError;
    case SwiUI::KSWInstErrBusy:
        return XQInstaller::BusyError;
    case SwiUI::KSWInstErrAccessDenied:
        return XQInstaller::AccessDeniedError;
    case SwiUI::KSWInstUpgradeError:
        return XQInstaller::UpgradeError;
    case SwiUI::KSWInstErrGeneralError:
    default:
        return XQInstaller::UnknownError;
    }    
}
 
// End of file
GetInstalledApps.h

#ifndef GETINSTALLEDAPPS_H
#define GETINSTALLEDAPPS_H

#include <QtGui/QMainWindow>
#include "ui_GetInstalledApps.h"
#include "xqinstaller.h"

class GetInstalledApps : public QMainWindow
{
    Q_OBJECT

public:
    GetInstalledApps(QWidget *parent = 0);
    ~GetInstalledApps();

private:
    void GetApps();
    
private:
    Ui::GetInstalledAppsClass ui;
    XQInstaller* m_installer;
    QMap<QString, uint> m_applications;
    QList<QString> m_appNames;
    QList<uint> m_appUID;
};

#endif // GETINSTALLEDAPPS_H
#ifndef XQINSTALLER_H
#define XQINSTALLER_H

// INCLUDES
#include <QObject>
#include <QMap>

class XQInstallerPrivate;

// CLASS DECLARATION
class XQInstaller : public QObject
{
    Q_OBJECT

public:
    enum Error {
        NoError = 0,
        OutOfMemoryError,
        AlreadyInUseError,
        UserCancelError, 
        PackageNotSupportedError,
        SecurityFailureError,
        MissingDependencyError,
        NoRightsError,
        BusyError,
        AccessDeniedError,
        UpgradeError,
        UnknownError = -1
    };
    
    enum Drive {
        DriveA,   DriveB,   DriveC,   DriveD,   DriveE,
        DriveF,   DriveG,   DriveH,   DriveI,   DriveJ,
        DriveK,   DriveL,   DriveM,   DriveN,   DriveO, 
        DriveP,   DriveQ,   DriveR,   DriveS,   DriveT,
        DriveU,   DriveV,   DriveW,   DriveX,   DriveY,
        DriveZ
    };

    XQInstaller(QObject *parent = 0);
    ~XQInstaller();
    
    bool install(const QString& file, XQInstaller::Drive drive = XQInstaller::DriveC);
    QMap<QString, uint> applications() const;
    bool remove(uint uid);

    XQInstaller::Error error() const;
    
Q_SIGNALS:
    void applicationInstalled();
    void applicationRemoved();
    void error(XQInstaller::Error);
    
private:
    friend class XQInstallerPrivate;
    XQInstallerPrivate *d;
};

#endif // XQINSTALLER_H
#ifndef XQINSTALLER_P_H
#define XQINSTALLER_P_H

// INCLUDES
#include "xqinstaller.h"
#include <SWInstApi.h>
#include <SWInstDefs.h>

// FORWARD DECLARATIONS
class QString;
class QFile;

// CLASS DECLARATION
class XQInstallerPrivate: public CActive
{

public:
    enum State {
        ERemove,
        EInstall
    };
    
    XQInstallerPrivate(XQInstaller *installer);
    ~XQInstallerPrivate();
    
    bool install(const QString& file, XQInstaller::Drive drive);
    bool remove(uint uid);
    QMap<QString, uint> applications() const;

public:
    XQInstaller::Error error();
    
protected:  
    void DoCancel();
    void RunL();

private:
    XQInstaller *q;
    mutable int iError;
    
    SwiUI::RSWInstSilentLauncher iLauncher;
    SwiUI::TInstallOptions iOptions;
    SwiUI::TInstallOptionsPckg iOptionsPckg;  
    
    SwiUI::TUninstallOptions iUninstallOptions;
    SwiUI::TUninstallOptionsPckg iUninstallOptionsPckg;
    XQInstallerPrivate::State iState;
    TFileName iFileName;
    bool iLauncherConnected;
};

#endif /*XQINSTALLER_P_H*/

// End of file
源代码:

CGulIcon* CMyClass::GetApplicationIconL(const TUid& aAppUID)
{
    CFbsBitmap* AppIcon(NULL);
    CFbsBitmap* AppIconMsk(NULL);
 
    MAknsSkinInstance* skin = AknsUtils::SkinInstance();
 
    AknsUtils::CreateAppIconLC(skin,aAppUID,  EAknsAppIconTypeContext,AppIcon,AppIconMsk);
    CleanupStack::Pop(2);
 
    return CGulIcon::NewL(AppIcon,AppIconMsk);
}

如果您无法获得解决方案或有任何疑问,请进行讨论

main.cpp

#include "GetInstalledApps.h"

#include <QtGui>
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    GetInstalledApps w;
    w.showMaximized();
    return a.exec();
}
#include "GetInstalledApps.h"
#include <QScrollArea>

GetInstalledApps::GetInstalledApps(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);
    setWindowTitle("GetAllInstalledApps");
    m_installer = new XQInstaller(this);
    GetApps();
    
}

void GetInstalledApps::GetApps()
{
    /* Get List of applications. 
     * type of m_applications is QMap<QString, uint>.
     * type of  m_installer is XQInstaller
     */
    m_applications = m_installer->applications();
    
    /* Get List of application names
     type of m_appNames is QList<QString> */
    m_appNames = m_applications.keys(); 
    
    /* Get List of application UID in decimal. 
    type of m_appUID is QList<uint> */
    m_appUID = m_applications.values(); 
    
    ui.listWidget->clear();
    for (int i = 0; i < m_appNames.count(); i++) 
    {
        QString str;
        /* convert UID from decimal to hex and then string. */
        str.setNum(m_appUID.at(i),16);
        /* append name and UID to string */     
        QString string(m_appNames.at(i)+"  UID:"+ str);
        /* append string to list widget to display on screen */
        ui.listWidget->addItem(string);
    }
    
    /* Let's make the UI scale so that we can scroll it. */
    QScrollArea* scrollArea = new QScrollArea;
    scrollArea->setWidget(ui.listWidget);
    scrollArea->setWidgetResizable(true);

    setCentralWidget(scrollArea);
}

GetInstalledApps::~GetInstalledApps()
{

}
#include "xqinstaller.h"
#include "xqinstaller_p.h"

/*!
    \class XQInstaller
    \brief The XQInstaller class is used to install sis-packages silently. 
    This extension can be used for example to install back-end applications.

    Example:
    \code
    XQInstaller *installer = new XQInstaller(this);
    QMap<QString, uint> applications = installer->applications();
    QListWidget *applicationList = new QListWidget(this);
    QList<QString> appNames = applications.keys();
    for (int i = 0; i < appNames.count(); i++) {
        applicationList->addItem(appNames.at(i));
    }   
    \endcode
*/

/*!
    Constructs a XQInstaller object with the given parent.
    \sa install(), remove()
*/
XQInstaller::XQInstaller(QObject *parent)
    : QObject(parent), d(new XQInstallerPrivate(this))
{
}

/*!
    Destroys the XQInstaller object.
*/
XQInstaller::~XQInstaller()
{
    delete d;
}

/*!
    Installs a sis package silently given as parameter.

    \param file Sis package
    \param drive Drive letter where the sis is installed to. Default value is 'C'.
    \return If false is returned, an error has occurred. Call error() to get a value of 
    XQInstaller::Error that indicates which error occurred
    \sa error()
*/  
bool XQInstaller::install(const QString& file, XQInstaller::Drive drive)
{
    return d->install(file, drive);
}

/*!
    Get list of installed applications
    If an empty QMap is returned, an error has possibly occurred. Call error() to get a value of 
    XQInstaller::Error that indicates which error occurred if any
    
    \return List of installed applications
    \sa error()
*/
QMap<QString, uint> XQInstaller::applications() const
{
    return d->applications();
}

/*!
    Removes application specified by the uid
   
    \param uid of the application
    \return True if removing was successfully started, otherwise false
    \sa error()
*/
bool XQInstaller::remove(uint uid)
{
    return d->remove(uid);
}

/*!
    \enum XQInstaller::Error

    This enum defines the possible errors for a XQInstaller object.
*/
/*! \var XQInstaller::Error XQInstaller::NoError
    No error occured.
*/
/*! \var XQInstaller::Error XQInstaller::OutOfMemoryError
    Not enough memory.
*/
/*! \var XQInstaller::Error XQInstaller::AlreadyInUseError
    Installer is already in used.
*/
/*! \var XQInstaller::Error XQInstaller::UserCancelError
    Installer cancelled by the user.
*/
/*! \var XQInstaller::Error XQInstaller::PackageNotSupportedError
    Package not supported
*/
/*! \var XQInstaller::Error XQInstaller::SecurityFailureError
    Security failure
*/
/*! \var XQInstaller::Error XQInstaller::MissingDependencyError
    Missing dependency
*/
/*! \var XQInstaller::Error XQInstaller::NoRightsError
    No rights
*/
/*! \var XQInstaller::Error XQInstaller::BusyError
    Installer is busy
*/
/*! \var XQInstaller::Error XQInstaller::AccessDeniedError
    Access denied
*/
/*! \var XQInstaller::Error XQInstaller::UpgradeError
    Error while upgrading
*/
/*! \var XQInstaller::Error XQInstaller::UnknownError
    Unknown error.
*/

/*!
    Returns the type of error that occurred if the latest function call failed; otherwise returns NoError
    \return Error code
*/
XQInstaller::Error XQInstaller::error() const
{
    return d->error();
}

/*!
    \fn void XQInstaller::applicationInstalled()

    This signal is emitted when the application has been installed.

    \sa install()
*/

/*!
    \fn void XQInstaller::error(XQInstaller::Error)

    This signal is emitted if error occured during the asynchronous operation

    \sa install()
*/

/*!
    \fn void XQInstaller::applicationRemoved()

    This signal is emitted when the application has been removed.

    \sa remove()
*/

// End of file
#include "xqinstaller.h"
#include "xqinstaller_p.h"
#include <f32file.h>
#include <apgcli.h>

XQInstallerPrivate::XQInstallerPrivate(XQInstaller *installer) 
    : CActive(EPriorityNormal), q(installer), iOptionsPckg(iOptions), 
      iUninstallOptionsPckg(iUninstallOptions), iLauncherConnected(false)
{
    CActiveScheduler::Add(this);  
}

XQInstallerPrivate::~XQInstallerPrivate()
{
    Cancel();
    if (iLauncherConnected) {
        iLauncher.Close();
    }
}

bool XQInstallerPrivate::install(const QString& file, XQInstaller::Drive drive)
{
    int asciiValue = 10;  // = 'A'
    TRAP(iError,
        if (!iLauncherConnected) {
            User::LeaveIfError(iLauncher.Connect());
            iLauncherConnected = true;
        }
        if (IsActive()) {
            User::Leave(KErrInUse);
        }
        
        iState = XQInstallerPrivate::EInstall;
        iOptions.iUpgrade = SwiUI::EPolicyAllowed;
        iOptions.iOCSP = SwiUI::EPolicyNotAllowed;
        iOptions.iDrive = TChar(asciiValue+drive);
        iOptions.iUntrusted = SwiUI::EPolicyAllowed; 
        iOptions.iCapabilities = SwiUI::EPolicyAllowed;  
        iOptions.iOptionalItems = SwiUI::EPolicyAllowed;  
        iOptions.iOverwrite = SwiUI::EPolicyAllowed; 
        TPtrC16 fileName(reinterpret_cast<const TUint16*>(file.utf16()));
        iFileName = fileName;
        iLauncher.SilentInstall(iStatus, iFileName, iOptionsPckg);
        SetActive();
    )
    return (iError == KErrNone);
}

bool XQInstallerPrivate::remove(uint uid)
{
    TRAP(iError,
        if (!iLauncherConnected) {
            User::LeaveIfError(iLauncher.Connect());
            iLauncherConnected = true;
        }
        if (IsActive()) {
            User::Leave(KErrInUse);
        }

        iState = XQInstallerPrivate::ERemove;
    
        iLauncher.SilentUninstall(iStatus,TUid::Uid(uid),
            iUninstallOptionsPckg, SwiUI::KSisxMimeType);
        SetActive();
    )
    return (iError == KErrNone);
}

QMap<QString, uint> XQInstallerPrivate::applications() const
{
    RApaLsSession lsSession;
    QMap<QString, uint> applications; 
      
    // Connect to application architecture server
    TRAP(iError,
        User::LeaveIfError(lsSession.Connect());
        CleanupClosePushL(lsSession);
        
        TApaAppInfo appInfo;
        lsSession.GetAllApps();  
        
        while (lsSession.GetNextApp(appInfo) == KErrNone) {
            TApaAppCapabilityBuf capability;
            User::LeaveIfError(lsSession.GetAppCapability(capability,
                appInfo.iUid));
            if (appInfo.iCaption.Length() > 0 && !capability().iAppIsHidden) {
                QString fullName = QString::fromUtf16(
                    appInfo.iCaption.Ptr(), appInfo.iCaption.Length());
                applications.insert(fullName, (TUint)appInfo.iUid.iUid);
            }
        }
        CleanupStack::PopAndDestroy(&lsSession);
    )
      
    return applications; 
}

void XQInstallerPrivate::DoCancel()
{
    if (iState == XQInstallerPrivate::EInstall) {
        iLauncher.CancelAsyncRequest(SwiUI::ERequestSilentInstall);
    } else if (iState == XQInstallerPrivate::ERemove) {
        iLauncher.CancelAsyncRequest(SwiUI::ERequestSilentUninstall);
    }
}
 
void XQInstallerPrivate::RunL()
{
    if (iStatus.Int() == KErrNone) {
        if (iState == XQInstallerPrivate::EInstall) {
            emit q->applicationInstalled();
        } else if (iState == XQInstallerPrivate::ERemove) {
            emit q->applicationRemoved();
        }
    } else {
        iError = iStatus.Int();
        emit q->error(error());
    }
}

XQInstaller::Error XQInstallerPrivate::error()
{
    switch (iError) {
    case KErrNone:
        return XQInstaller::NoError;
    case SwiUI::KSWInstErrInsufficientMemory:
    case KErrNoMemory:
        return XQInstaller::OutOfMemoryError;
    case SwiUI::KSWInstErrFileInUse:
    case KErrInUse:
        return XQInstaller::AlreadyInUseError;
    case SwiUI::KSWInstErrUserCancel:
        return XQInstaller::UserCancelError;  
    case SwiUI::KSWInstErrPackageNotSupported:
        return XQInstaller::PackageNotSupportedError; 
    case SwiUI::KSWInstErrSecurityFailure:
        return XQInstaller::SecurityFailureError; 
    case SwiUI::KSWInstErrMissingDependency:
        return XQInstaller::MissingDependencyError; 
    case SwiUI::KSWInstErrNoRights:
        return XQInstaller::NoRightsError;
    case SwiUI::KSWInstErrBusy:
        return XQInstaller::BusyError;
    case SwiUI::KSWInstErrAccessDenied:
        return XQInstaller::AccessDeniedError;
    case SwiUI::KSWInstUpgradeError:
        return XQInstaller::UpgradeError;
    case SwiUI::KSWInstErrGeneralError:
    default:
        return XQInstaller::UnknownError;
    }    
}
 
// End of file
GetInstalledApps.h

#ifndef GETINSTALLEDAPPS_H
#define GETINSTALLEDAPPS_H

#include <QtGui/QMainWindow>
#include "ui_GetInstalledApps.h"
#include "xqinstaller.h"

class GetInstalledApps : public QMainWindow
{
    Q_OBJECT

public:
    GetInstalledApps(QWidget *parent = 0);
    ~GetInstalledApps();

private:
    void GetApps();
    
private:
    Ui::GetInstalledAppsClass ui;
    XQInstaller* m_installer;
    QMap<QString, uint> m_applications;
    QList<QString> m_appNames;
    QList<uint> m_appUID;
};

#endif // GETINSTALLEDAPPS_H
#ifndef XQINSTALLER_H
#define XQINSTALLER_H

// INCLUDES
#include <QObject>
#include <QMap>

class XQInstallerPrivate;

// CLASS DECLARATION
class XQInstaller : public QObject
{
    Q_OBJECT

public:
    enum Error {
        NoError = 0,
        OutOfMemoryError,
        AlreadyInUseError,
        UserCancelError, 
        PackageNotSupportedError,
        SecurityFailureError,
        MissingDependencyError,
        NoRightsError,
        BusyError,
        AccessDeniedError,
        UpgradeError,
        UnknownError = -1
    };
    
    enum Drive {
        DriveA,   DriveB,   DriveC,   DriveD,   DriveE,
        DriveF,   DriveG,   DriveH,   DriveI,   DriveJ,
        DriveK,   DriveL,   DriveM,   DriveN,   DriveO, 
        DriveP,   DriveQ,   DriveR,   DriveS,   DriveT,
        DriveU,   DriveV,   DriveW,   DriveX,   DriveY,
        DriveZ
    };

    XQInstaller(QObject *parent = 0);
    ~XQInstaller();
    
    bool install(const QString& file, XQInstaller::Drive drive = XQInstaller::DriveC);
    QMap<QString, uint> applications() const;
    bool remove(uint uid);

    XQInstaller::Error error() const;
    
Q_SIGNALS:
    void applicationInstalled();
    void applicationRemoved();
    void error(XQInstaller::Error);
    
private:
    friend class XQInstallerPrivate;
    XQInstallerPrivate *d;
};

#endif // XQINSTALLER_H
#ifndef XQINSTALLER_P_H
#define XQINSTALLER_P_H

// INCLUDES
#include "xqinstaller.h"
#include <SWInstApi.h>
#include <SWInstDefs.h>

// FORWARD DECLARATIONS
class QString;
class QFile;

// CLASS DECLARATION
class XQInstallerPrivate: public CActive
{

public:
    enum State {
        ERemove,
        EInstall
    };
    
    XQInstallerPrivate(XQInstaller *installer);
    ~XQInstallerPrivate();
    
    bool install(const QString& file, XQInstaller::Drive drive);
    bool remove(uint uid);
    QMap<QString, uint> applications() const;

public:
    XQInstaller::Error error();
    
protected:  
    void DoCancel();
    void RunL();

private:
    XQInstaller *q;
    mutable int iError;
    
    SwiUI::RSWInstSilentLauncher iLauncher;
    SwiUI::TInstallOptions iOptions;
    SwiUI::TInstallOptionsPckg iOptionsPckg;  
    
    SwiUI::TUninstallOptions iUninstallOptions;
    SwiUI::TUninstallOptionsPckg iUninstallOptionsPckg;
    XQInstallerPrivate::State iState;
    TFileName iFileName;
    bool iLauncherConnected;
};

#endif /*XQINSTALLER_P_H*/

// End of file
源代码:

CGulIcon* CMyClass::GetApplicationIconL(const TUid& aAppUID)
{
    CFbsBitmap* AppIcon(NULL);
    CFbsBitmap* AppIconMsk(NULL);
 
    MAknsSkinInstance* skin = AknsUtils::SkinInstance();
 
    AknsUtils::CreateAppIconLC(skin,aAppUID,  EAknsAppIconTypeContext,AppIcon,AppIconMsk);
    CleanupStack::Pop(2);
 
    return CGulIcon::NewL(AppIcon,AppIconMsk);
}

很抱歉,无法添加太多超链接,因为我的重复率仍然很低:/-1获取应用程序名称和uid的链接与问题中提到的相同,甚至无法编译。您是否尝试过使用TApaAppInfo?是的,我尝试过,但无法理解任何内容。如果您有任何示例/工作代码,请更新。抱歉,无法添加太多超链接,因为我的代表性仍然很低:/-1获取应用程序名称和uid的链接与问题中提到的相同,甚至无法编译。您是否尝试过使用TApaAppInfo?是的,我尝试过,但无法理解任何内容。如果您有任何示例/工作代码,请更新它。请在给出任何答案之前参考所有三个链接,该链接中的代码不会编译。请在给出任何答案之前参考所有三个链接,该链接中的代码不会编译。