Why linker error 2019 when linking to GoogleBreakpad? - qt

After a few hours of digging for this linker error, it wasn't successful:(
Steps to reproduce:
Install gyp and it to PATH
Open VS2015 x86 Native Tools Command Prompt
Run:
git clone https://chromium.googlesource.com/breakpad/breakpad && cd breakpad
cd src && git clone https://github.com/google/googletest testing && cd ..
gyp -–no-circular-check src\client\windows\breakpad_client.gyp
Open src\client\windows\breakpad_client.sln
Go to projects Properties>C/C++/General and change Treat Warnings
As Errors to No for crash_generation_client, common, exception_handler
for Debug and Release configuration
Go to projects Properties>C/C++/General and change Treat wchar_t as
Built-in Type to No for crash_generation_client, common,
exception_handler for Debug and Release configuration
Buil all for Debug
Build all for Release
Link the libs located in breakpad\src\client\windows\Debug\lib and breakpad\src\client\windows\Release\lib to
your application, in my case the Qt qmake file like below:
win32:debug {
BREAKPAD_PATH = $$PWD/../../../LIBS/breakpad
INCLUDEPATH += $$BREAKPAD_PATH/src
LIBS += -L$$BREAKPAD_PATH/client/windows/Debug/lib/crash_generation_client.lib
LIBS += -L$$BREAKPAD_PATH/client/windows/Debug/lib/exception_handler.lib
LIBS += -L$$BREAKPAD_PATH/client/windows/Debug/lib/common.lib
PRE_TARGETDEPS += $$BREAKPAD_PATH/client/windows/Debug/lib/crash_generation_client.lib
PRE_TARGETDEPS += $$BREAKPAD_PATH/client/windows/Debug/lib/exception_handler.lib
PRE_TARGETDEPS += $$BREAKPAD_PATH/client/windows/Debug/lib/common.lib
} else:release {
BREAKPAD_PATH = $$PWD/../../../LIBS/breakpad
INCLUDEPATH += $$BREAKPAD_PATH/src
LIBS += -L$$BREAKPAD_PATH/client/windows/Release/lib/crash_generation_client.lib
LIBS += -L$$BREAKPAD_PATH/client/windows/Release/lib/exception_handler.lib
LIBS += -L$$BREAKPAD_PATH/client/windows/Release/lib/common.lib
PRE_TARGETDEPS += $$BREAKPAD_PATH/client/windows/Release/lib/crash_generation_client.lib
PRE_TARGETDEPS += $$BREAKPAD_PATH/client/windows/Release/lib/exception_handler.lib
PRE_TARGETDEPS += $$BREAKPAD_PATH/client/windows/Release/lib/common.lib
}
The linker should prompt you by the following error:
crash_handler.obj : error LNK2019: unresolved external symbol "public:
__thiscall google_breakpad::ExceptionHandler::ExceptionHandler(class std::basic_string,class
std::allocator > const &,bool (__cdecl*)(void *,struct
_EXCEPTION_POINTERS *,struct MDRawAssertionInfo ),bool (__cdecl)(wchar_t const *,wchar_t const *,void *,struct
_EXCEPTION_POINTERS *,struct MDRawAssertionInfo *,bool),void *,int)" (??0ExceptionHandler#google_breakpad##QAE#ABV?$basic_string#_WU?$char_traits#_W#std##V?$allocator#_W#2##std##P6A_NPAXPAU_EXCEPTION_POINTERS##PAUMDRawAssertionInfo###ZP6A_NPB_W5123_N#Z1H#Z)
referenced in function "public: void __thiscall
breakpad::CrashHandlerPrivate::initCrashHandler(class QString const
&)"
(?initCrashHandler#CrashHandlerPrivate#breakpad##QAEXABVQString###Z)
crash_handler.obj : error LNK2019: unresolved external symbol "public:
__thiscall google_breakpad::ExceptionHandler::~ExceptionHandler(void)" (??1ExceptionHandler#google_breakpad##QAE#XZ) referenced in function
"public: void * __thiscall google_breakpad::ExceptionHandler::`scalar
deleting destructor'(unsigned int)"
(??_GExceptionHandler#google_breakpad##QAEPAXI#Z) crash_handler.obj :
error LNK2019: unresolved external symbol "public: bool __thiscall
google_breakpad::ExceptionHandler::WriteMinidump(void)"
(?WriteMinidump#ExceptionHandler#google_breakpad##QAE_NXZ) referenced
in function "public: bool __thiscall
breakpad::CrashHandler::writeMinidump(void)"
(?writeMinidump#CrashHandler#breakpad##QAE_NXZ)
crash_handler.h:
#ifndef _CRASH_HANDLER_H
#define _CRASH_HANDLER_H
namespace breakpad {
class CrashHandlerPrivate;
class CrashHandler {
public:
static CrashHandler* instance();
void init(const QString& reportPath);
void setReportCrashesToSystem(bool report);
bool writeMinidump();
private:
CrashHandler();
~CrashHandler();
private:
CrashHandlerPrivate* d;
Q_DISABLE_COPY(CrashHandler)
};
} // namespace breakpad
#endif // !_CRASH_HANDLER_H
crash_handler.cpp
#include "crash_handler.h"
#if defined(Q_OS_LINUX)
#include "client/linux/handler/exception_handler.h"
#elif defined(Q_OS_WIN32)
#include "client/windows/handler/exception_handler.h"
#endif
namespace breakpad {
class CrashHandlerPrivate {
public:
CrashHandlerPrivate() {
pHandler = NULL;
}
~CrashHandlerPrivate() {
delete pHandler;
}
void initCrashHandler(const QString& dumpPath);
public:
static google_breakpad::ExceptionHandler* pHandler;
static bool bReportCrashesToSystem;
};
google_breakpad::ExceptionHandler* CrashHandlerPrivate::pHandler = NULL;
bool CrashHandlerPrivate::bReportCrashesToSystem = false;
/************************************************************************/
/* DumpCallback */
/************************************************************************/
#if defined(Q_OS_WIN32)
bool DumpCallback(const wchar_t* _dump_dir, const wchar_t* _minidump_id, void* context, EXCEPTION_POINTERS* exinfo, MDRawAssertionInfo* assertion, bool success)
#elif defined(Q_OS_LINUX)
bool DumpCallback(const google_breakpad::MinidumpDescriptor &md, void *context, bool success)
#endif
{
Q_UNUSED(context);
#if defined(Q_OS_WIN32)
Q_UNUSED(_dump_dir);
Q_UNUSED(_minidump_id);
Q_UNUSED(assertion);
Q_UNUSED(exinfo);
#endif
qDebug("BreakpadQt crash");
/*
NO STACK USE, NO HEAP USE THERE !!!
Creating QString's, using qDebug, etc. - everything is crash-unfriendly.
*/
return CrashHandlerPrivate::bReportCrashesToSystem ? success : true;
}
void CrashHandlerPrivate::initCrashHandler(const QString& dumpPath)
{
if (pHandler != NULL)
return;
#if defined(Q_OS_WIN32)
std::wstring pathAsStr = (const wchar_t*)dumpPath.utf16();
pHandler = new google_breakpad::ExceptionHandler(
pathAsStr,
/*FilterCallback*/ 0,
DumpCallback,
/*context*/
0,
true
);
#elif defined(Q_OS_LINUX)
std::string pathAsStr = dumpPath.toStdString();
google_breakpad::MinidumpDescriptor md(pathAsStr);
pHandler = new google_breakpad::ExceptionHandler(
md,
/*FilterCallback*/ 0,
DumpCallback,
/*context*/ 0,
true,
-1
);
#endif
}
CrashHandler* CrashHandler::instance() {
static CrashHandler globalHandler;
return &globalHandler;
}
CrashHandler::CrashHandler() {
d = new CrashHandlerPrivate();
}
CrashHandler::~CrashHandler() {
delete d;
}
void CrashHandler::setReportCrashesToSystem(bool report) {
d->bReportCrashesToSystem = report;
}
bool CrashHandler::writeMinidump() {
bool res = d->pHandler->WriteMinidump();
if (res) {
qDebug("BreakpadQt: writeMinidump() success.");
} else {
qWarning("BreakpadQt: writeMinidump() failed.");
}
return res;
}
void CrashHandler::init(const QString& reportPath) {
d->initCrashHandler(reportPath);
}
} // namespace breakpad
Really don't know what the problem is ?!
Configuration:
OS: Windows 10(1809)
Build system: MSVC14.0(2015)
Qt version: 5.8(32bit)

Related

pcl_visualizer.h - fatal error LNK1120: 1 unresolved externals

error LNK2001: unresolved external symbol "public: virtual void __cdecl pcl::visualization::PCLVisualizer::FPSCallback::Execute(class vtkObject *,unsigned long,void *)" (?Execute#FPSCallback#PCLVisualizer#visualization#pcl##UEAAXPEAVvtkObject##KPEAX#Z)
1>C:\Users\hatea\Documents\Visual Studio 2015\Projects\PCLTester\x64\Debug\PCLTester.dll : fatal error LNK1120: 1 unresolved externals
I have thoroughly exhausted all avenues dealing with this issue. I checked here, and I found a similar question/answer series: error LNK2001 when including "pcl_visualizer.h"
The problem is that I do not want to comment out the FPSCallback method. I need it for the VTK visualizer I am using. I have determined that I only receive the unresolved external error when I reference the .h file in a managed C++/CLI library.
#pragma once
#pragma unmanaged
#include <pcl/visualization/pcl_visualizer.h>
#pragma managed
using namespace System;
namespace PCLTesterCLI
{
public ref class PCLTesterCLI
{
public:
PCLTesterCLI();
virtual ~PCLTesterCLI();
};
}
If I do the same in an unmanaged Win32 library, the library is successfully built.
#pragma once
#include <pcl/visualization/pcl_visualizer.h>
class PCLTester
{
public:
PCLTester();
virtual ~PCLTester();
};
Here is the segment from pcl_visualizer.h:
struct FPSCallback : public vtkCommand
{
static FPSCallback *New () { return (new FPSCallback); }
FPSCallback () : actor (), pcl_visualizer (), decimated () {}
FPSCallback (const FPSCallback& src) : vtkCommand (), actor (src.actor), pcl_visualizer (src.pcl_visualizer), decimated (src.decimated) {}
FPSCallback& operator = (const FPSCallback& src) { actor = src.actor; pcl_visualizer = src.pcl_visualizer; decimated = src.decimated; return (*this); }
virtual void
Execute (vtkObject*, unsigned long event_id, void*);
vtkTextActor *actor;
PCLVisualizer* pcl_visualizer;
bool decimated;
};
/** \brief The FPSCallback object for the current visualizer. */
vtkSmartPointer<FPSCallback> update_fps_;
Here is the segment from pcl_visualizer.cpp:
void
pcl::visualization::PCLVisualizer::FPSCallback::Execute (
vtkObject* caller, unsigned long, void*)
{
vtkRenderer *ren = reinterpret_cast<vtkRenderer *> (caller);
float fps = 1.0f / static_cast<float> (ren->GetLastRenderTimeInSeconds ());
char buf[128];
sprintf (buf, "%.1f FPS", fps);
actor->SetInput (buf);
}
Any ideas why the structure and member function conflict in a managed environment?
The reason that my question is unique is that my symbols error was not a result of anything I did: e.g. declaring a function without defining it, having a syntax error that results in the function not being properly defined, or leaving out a .lib dependency from Linker->Input. In my case, I have all the correct .lib files linked and the function from pcl::visualization seems well defined. For some strange reason, it is still being missed at compile time in the managed library. I copied my dependencies from my managed .vcxproj to my unmanaged .vcxproj to verify that it was not a dependency issue. Both classes are setup with the minimum class requirements to prevent conflicts in that regard. Both projects have the same .h file and .lib files linked.
Interestingly, I solved this issue by placing the pcl_visualizer code into my managed c++ code at the top. I had to add a header as well:
#include <vtkTextActor.h>
void
pcl::visualization::PCLVisualizer::FPSCallback::Execute(vtkObject* caller, unsigned long, void*)
{
vtkRenderer *ren = reinterpret_cast<vtkRenderer *> (caller);
float fps = 1.0f / static_cast<float> (ren->GetLastRenderTimeInSeconds());
char buf[128];
sprintf(buf, "%.1f FPS", fps);
actor->SetInput(buf);
}
The other option is to go into pcl_visualizer.h and comment out the offending line (I do not know why this line causes issues, but I narrowed it down to this, and my vtk visualizer still works!):
//FPSCallback (const FPSCallback& src) : vtkCommand (), actor (src.actor), pcl_visualizer (src.pcl_visualizer), decimated (src.decimated) {}
The code then looks like:
struct FPSCallback : public vtkCommand
{
static FPSCallback *New () { return (new FPSCallback); }
FPSCallback () : actor (), pcl_visualizer (), decimated () {}
//FPSCallback (const FPSCallback& src) : vtkCommand (), actor (src.actor), pcl_visualizer (src.pcl_visualizer), decimated (src.decimated) {}
FPSCallback& operator = (const FPSCallback& src) { actor = src.actor; pcl_visualizer = src.pcl_visualizer; decimated = src.decimated; return (*this); }
virtual void
Execute (vtkObject*, unsigned long event_id, void*);
vtkTextActor *actor;
PCLVisualizer* pcl_visualizer;
bool decimated;
};
/** \brief The FPSCallback object for the current visualizer. */
vtkSmartPointer<FPSCallback> update_fps_;

What is this error about?

ALL,
I'm using Anjuta to do my development.
I created a project for my main application, and then made 2 more: 1 for the static library (libdbinterface.a) and 1 for the dynamic library (libsqlite_lib.so).
Both those libraries contains one exported class each: libdbinterface.a - class Database, libsqlite_lib.so - public SQLiteDatabase : public Database.
Now I'm trying to link libdbinterface.a to libsqlite_lib.so.
So in Anjuta I added following to the "Linker Option" for the target libsqlite_lib.so:
-L/home/igor/dbhandler/Debug/dbinterface -ldbinterface
However, trying to compile I received following error from linker:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.4/../../../../x86_64-pc-linux-gnu/bin/ld: /home/igor/dbhandler/Debug/dbinterface/libdbinterface.a(database.o): relocation R_X86_64_32S against `_ZTV8Database' can not be used when making a shared object; recompile with -fPIC
I tried to recompile libsqlite_lib.so with -fPIC explicitely added to "C++ Options" of that project but that didn't solve it - I still receive the same error.
Unfortunately trying to Google on how to link .a and .so is not helpful.
Can someone sched some light on how to fix this error?
TIA.
[EDIT]
libsqlite_lib.so Makefile - https://bpaste.net/show/1495231e58cc
libdbinterface.a Makefile - https://bpaste.net/show/3a71c119d0fc
libdbinterface.a contains 2 files databse.h:
#ifndef DBMANAGER_DATABASE
#define DBMANAGER_DATABASE
class Field
{
public:
Field(const std::string &columnName, const std::string &columnType, const std::string &columnDefaultValue = "", const bool columnIsNull = false, const bool columnPK = false)
{
column_name = columnName;
column_type = columnType;
column_defaultValue = columnDefaultValue;
column_isNull = columnIsNull;
column_pk = columnPK;
}
private:
std::string column_name, column_type, column_defaultValue;
bool column_isNull, column_pk;
};
struct FKField
{
FKField(const std::string &table_name, const std::string &original_field, const std::string &referenced_field)
{
tableName = table_name;
originalField = original_field;
referencedField = referenced_field;
}
std::string tableName, originalField, referencedField;
};
class Table
{
public:
Table(const std::string &tableName, const std::vector<Field> &tableFields, const std::map<int,std::vector<FKField> > &foreignKeys)
{
table_name = tableName;
table_fields = tableFields;
foreign_keys = foreignKeys;
}
const std::string &GetTableName() { return table_name; }
std::map<int,std::vector<FKField> > &GetForeignKeyVector() { return foreign_keys; }
private:
std::string table_name;
std::vector<Field> table_fields;
std::map<int,std::vector<FKField> > foreign_keys;
};
#ifdef WIN32
class __declspec(dllexport) Database
#else
class Database
#endif
{
private:
struct Impl;
Impl *pimpl;
public:
Database();
virtual ~Database();
Impl &GetTableVector();
static void *operator new(std::size_t size);
static void operator delete(void *ptr, std::size_t size);
virtual int Connect(const char *selectedDSN, std::vector<std::wstring> &errorMsg);
virtual int GetTableListFromDb(std::string &) { return 0; }
};
#endif
and database.cpp:
#ifdef WIN32
#include <windows.h>
#endif
#include <map>
#include <vector>
#include <string>
#include <sqlext.h>
#include "database.h"
struct Database::Impl
{
std::vector<Table> m_tables;
};
Database::Database() : pimpl( new Impl )
{
}
Database::~Database()
{
delete pimpl;
}
void *Database::operator new(std::size_t size)
{
return ::operator new( size );
}
void Database::operator delete(void *ptr, std::size_t size)
{
return ::operator delete( ptr );
}
Database::Impl &Database::GetTableVector()
{
return *pimpl;
}
int Database::Connect(const char *selectedDSN, std::vector<std::wstring> &errorMsg)
{
selectedDSN = selectedDSN;
errorMsg = errorMsg;
return 0;
}
libsqlite_lib.so has also 2 files: database_sqlite.h
#ifndef DBMANAGER_SQLITE
#define DBMANAGER_SQLITE
#ifdef WIN32
class __declspec(dllexport) SQLiteDatabase : public Database
#else
class SQLiteDatabase : public Database
#endif
{
public:
SQLiteDatabase();
~SQLiteDatabase();
virtual int Connect(const char *selectedDSN, std::vector<std::wstring> &errorMsg);
virtual int GetTableListFromDb(std::vector<std::wstring> &errorMsg);
protected:
void GetErrorMessage(int code, std::wstring &errorMsg);
private:
sqlite3 *m_db;
};
#endif
and database_sqlite.cpp with the actual implementation.
[/EDIT]
Well, apparently the solution is to rebuild static library with "-fPIC", not the dynamic one.
Thank you for reading.

Cannot import QML plugin

Let's consider an example QML plugin PluginExample (see C++ Plugins for QML) created in the directory $HOME/projects/org/example/PluginExample ($HOME/projects is in QML2_IMPORT_PATH).
pluginexample.pro:
TEMPLATE = lib
TARGET = PluginExample
QT += qml quick
CONFIG += qt plugin
TARGET = $$qtLibraryTarget($$TARGET)
uri = org.example.PluginExample
# Input
SOURCES += \
pluginexample_plugin.cc \
myitem.cc
HEADERS += \
pluginexample_plugin.hh \
myitem.hh
OTHER_FILES = qmldir
!equals(_PRO_FILE_PWD_, $$OUT_PWD) {
copy_qmldir.target = $$OUT_PWD/qmldir
copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir
copy_qmldir.commands = $(COPY_FILE) \"$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)\"
QMAKE_EXTRA_TARGETS += copy_qmldir
PRE_TARGETDEPS += $$copy_qmldir.target
}
qmldir.files = qmldir
unix {
installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /)
qmldir.path = $$installPath
target.path = $$installPath
INSTALLS += target qmldir
}
myitem.hh:
#ifndef MYITEM_H
#define MYITEM_H
#include <QQuickItem>
class MyItem : public QQuickItem
{
Q_OBJECT
Q_DISABLE_COPY(MyItem)
Q_PROPERTY(QString text READ text CONSTANT)
public:
MyItem(QQuickItem *parent = 0);
QString text() const;
~MyItem();
};
#endif // MYITEM_H
myitem.cc:
#include "myitem.hh"
MyItem::MyItem(QQuickItem *parent):
QQuickItem(parent)
{
}
MyItem::~MyItem()
{
}
QString MyItem::text() const
{
return "MyItem";
}
pluginexample_plugin.hh:
#ifndef PLUGINEXAMPLE_PLUGIN_H
#define PLUGINEXAMPLE_PLUGIN_H
#include <QQmlExtensionPlugin>
class PluginExamplePlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
public:
void registerTypes(const char *uri);
};
#endif // PLUGINEXAMPLE_PLUGIN_H
pluginexample_plugin.cc:
#include "pluginexample_plugin.hh"
#include "myitem.hh"
#include <qqml.h>
void PluginExamplePlugin::registerTypes(const char *uri)
{
// #uri org.example.PluginExample
qmlRegisterType<MyItem>(uri, 1, 0, "MyItem");
}
qmldir:
module org.example.PluginExample
plugin PluginExample
The most part of the plugin's code was auto-generated by the project wizard.
It builds fine, but when I try to import org.example.PluginExample 1.0 from another project, I get this error:
module "org.example.PluginExample" plugin "PluginExample" not found
How can I fix that? Do I need to specify additional information to build/locate the plugin?
PS. Qt 5.3, Linux x86_64
EDIT 1:
I copied libPluginExample.so from the build directory (build-PluginExample-Desktop_Qt_5_3_0_GCC_64bit-Debug) to the source directory (PluginExample), and the error disappeared. Is this the best solution?
EDIT 2:
To avoid manual copying of the plugin library after each build, the following changes need to be applied to the *.pro file (unix-specific):
!equals(_PRO_FILE_PWD_, $$OUT_PWD) {
# ...
unix {
QMAKE_POST_LINK += $(COPY_FILE) $$quote($${OUT_PWD}/lib$${TARGET}.so) $$_PRO_FILE_PWD_
}
}

How to get list of application icons which are installed in device with Qt

I am working with Qt application in which I want to create a QListWidget with names of all application installed on device and its icon.
So I was unable get all application names and UID of each application from the code in this LINK.
But I was also unable to get the application icons. I tried both this LINK1 & LINK2 but here I came across few more issues like how to convert CGulIcon into QIcon & CApaMaskedBitmap into QIcon.
How can I do this?
If you are unable to get the solution or have any more doubts click here for disscussion.
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();
}
.pro
TEMPLATE = app
TARGET = GetInstalledApps
QT += core \
gui
HEADERS += GetInstalledApps.h
SOURCES += main.cpp \
GetInstalledApps.cpp
FORMS += GetInstalledApps.ui
RESOURCES +=
HEADERS += xqinstaller_p.h \
xqinstaller.h \
SOURCES += xqinstaller_p.cpp \
xqinstaller.cpp
symbian:LIBS += -lswinstcli \
-lcommdb \
-lapparc \
-lefsrv \
-lapgrfx \
symbian:TARGET.CAPABILITY += TrustedUI
symbian:TARGET.UID3 = 0xEF3055F4
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
GetInstalledApps.cpp
#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()
{
}
xqinstaller.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
xqinstaller.cpp
#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
xqinstaller_h.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
xqinstaller_h.cpp
#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
And for getting QIcon::
Hearders Required:
#include <fbs.h> //CFbsBitmap
#include <aknsskininstance.h> //MAknsSkinInstance
#include <aknsutils.h> //AknsUtils
Library required:
LIBRARY fbscli.lib ///CFbsBitmap
LIBRARY aknskins.lib aknskinsrv.lib aknswallpaperutils.lib //MAknsSkinInstance ,AknsUtils
Source Code:
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);
}
Well, for the icon thing look at this: CGullIcon there's a function that returns the Bitmap, a CFbsBitmap. Once you've done that look at this: http://qt-project.org/doc/qt-4.8/qpixmap.html#fromSymbianCFbsBitmap then you create a new QIcon(QPixmap) (QPixmap = the icon you've transformed). So most likely you're first passing it to a CFbsBitmap and then with QPixmap you use fromSymibnaCFbsBitmap().
CApaMaskedBitmap is a sub-class of CFbsBitmap if i'm not wrong, so it should work the same.
And for getting the applications and their UID try to look at this: http://www.developer.nokia.com/Community/Wiki/Get_list_of_installed_applications_and_its_UID_in_Qt

Linker error: Qt and libusb-win32

I try to develop a Qt GUI application which will communicate with a board using USB. The library I use is libusb-win32 v1.2.5.0.
When I compile the application, the following errors occur:
./debug/thread_usb_comm.o: In function `ZN15thread_usb_comm15find_usb_deviceEtt':
thread_usb_comm.cpp:15: undefined reference to 'usb_find_busses'
thread_usb_comm.cpp:16: undefined reference to 'usb_find_devices'
thread_usb_comm.cpp:18: undefined reference to 'usb_get_busses'
thread_usb_comm.cpp:26: undefined reference to 'usb_open'
collect2: ld returned 1 exit status
mingw32-make[1]: [debug/CALSYS11_calib_app.exe] Error 1
mingw32-make: [debug] Error 2
The application code is:
(header file)
#ifndef THREAD_USB_COMM_H
#define THREAD_USB_COMM_H
#include <QThread>
#include <QtDebug>
#include "CALSYS11.h"
#include <lusb0_usb.h>
class thread_usb_comm : public QThread
{
Q_OBJECT
public:
thread_usb_comm();
private:
bool device_connected;
usb_dev_handle *p_usb_device;
bool find_usb_device(
unsigned short vendor_id,
unsigned short product_id
);
};
#endif // THREAD_USB_COMM_H
(source file)
#include "thread_usb_comm.h"
thread_usb_comm::thread_usb_comm()
{
device_connected = false;
}
bool thread_usb_comm::find_usb_device(
unsigned short vendor_id,
unsigned short product_id
)
{
struct usb_bus *bus;
struct usb_device *dev;
usb_find_busses();
usb_find_devices();
for (bus = usb_get_busses(); bus; bus = bus->next)
{
for (dev = bus->devices; dev; dev = dev->next)
{
if ((dev->descriptor.idVendor == vendor_id) &&
(dev->descriptor.idProduct == product_id))
{
qDebug ("Device found");
p_usb_device = usb_open(dev);
if (0 == p_usb_device)
{
qCritical ("Could not open USB device");
return false;
}
device_connected = true;
return true;
}
}
}
qDebug ("Cannot find specified device");
return false;
}
I added the link to the libusb library in the .pro file:
LIBS += -L\path\to\libusb-win32\lib\gcc -lusb
I develop on Windows 7.
Thank you,
Johann
Try to build release instead of debug or the static library is incompatible with compiler version (I faced same issue when I tried to build old static library with MinGW 4.4)

Resources