I have plugin and i want static link it with my app.
In plugin.pro file i have:
TEMPLATE = lib
CONFIG += staticlib
In plugin.cpp:
Q_EXPORT_PLUGIN2(plugin, pluginClass)
Of course TARGET in .pro file is the same as plugin name.
In myapp.pro file:
LIBS += libplugin.a
main.cpp:
#include <QtGui/QApplication>
#include <QtPlugin>
Q_IMPORT_PLUGIN(plugin)
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
...
return a.exec();
}
Plugin compiles without errors, i got *.a and *.o files, so i copied *.a file to myapp directory and when i trying compile i get error like this:
cannot find -lmyplugin.a
collect2: ld returned 1 exit status
So i gave full path to libplugin.a in myapp.pro file and i got in the line with Q_IMPORT_PLUGIN error:
undefined reference to `qt_plugin_instance_plugin()'
and much errors like this:
undefined reference to `pluginClass::function()'
I included *.h file of my plugin.
What am I doing wrong?
In your plugin .pro file use this code:
CONFIG += plugin static
instead of
CONFIG += staticlib
Related
I have yocto dev environment setup, in which I can bitbake and run a simple c++ application in the target. Now I want to try with simple Qt application. When I execute bitbake-layers show-layers it shows meta-qt5 in the list...
meta-qt5
/home/prc1cob/repo/out/salt/kawa/../../..//os/external/meta-qt5 7
meta-oe
/home/prc1cob/repo/out/salt/kawa/../../../build/yocto/meta-openembedded/meta-oe
6
With this, I assume qt5 is already present in my yocto build.
How to write .bb file to build a simple HelloWorld qt application as below...
#include <QCoreApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << "Hello World";
return a.exec();
}
Thankyou!!
Yocto provides a great class qmake5 to compile QT projects based on QMake.
In order to use it create a .pro file for the project:
qtexample.pro
QT += core
SOURCES += qtexample.cpp
qtexample.cpp
#include <QCoreApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << "Hello World";
return a.exec();
}
Now, in your layer, you can add a simple recipe that compiles that project.
For example: meta-custom/recipes-project/qtexample
In qtexample folder create files folder and copy qtexample.pro and qtexample.cpp in it.
In qtexample folder directly create qtexample_0.1.bb recipe:
SUMMARY = "QT Example Recipe"
LICENSE = "CLOSED"
SRC_URI = "file://qtexample.pro \
file://qtexample.cpp"
DEPENDS += "qtbase"
RDEPENDS_${PN} += "qtwayland"
S = "${WORKDIR}"
inherit qmake5
You can change the version ofcourse (0.1).
The layout should look like this:
meta-custom/
├── recipes-project/
├── qtexample_0.1.bb
└── files/
├── qtexample.pro
└── qtexample.cpp
Then, bitbake qtexample should work and create a qtexample binary that you can find in ${WORKDIR}
no matter what i try, the translator wont load the translation file and keeps showing only ids instead of the translation
i have triad everything i could posibly google up
#include <QQmlApplicationEngine>
#include <QGuiApplication>
#include <QtQml>
#include <QTranslator>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
QTranslator translator;
translator.load(QLocale(), "c:/asteroid/asteroid-sporttracking-master", ".", "i18n", ".gm");
app.installTranslator(&translator);
return app.exec();
}
the full path for the translation file is:
c:\asteroid\asteroid-sporttracking-master\i18n\asteroid-sportapp.en_GB.ts
- there are files with multipla local() -en_GB/cs/etc
so is there a way to console.log() the virtual variable created by translator.load()?
So after all I found out the file with translation must be in directory where the debugger will compile the executable file, not with the code directory
You are confusing QM and TS Files. You need to use lupdate and lrelease tools. lupdate to create and update the TS files and then lrelease to generate QM files. The application will use QM files.
In your code the path and filename has to be entered because the system didn't find the QM Files but Isn't a good idea using absolute path. Please see my example:
String filename = QString("app.qm");
QString path = QApplication::applicationDirPath();
if(translator.load(path + filename)){
qApp->installTranslator(&translator);
}
I am relatively new to Qt and was going through many tutorials. Everything was fine. All scripts compiled and ran.
Then, at some point, I am getting the error for even a new Qt widget application created with Qt Creator 4.3.1:
C:\ \Documents\111\main.cpp:-1: In function 'int qMain(int, char**)':
C:\ \Documents\111\main.cpp:6: error: variable 'QApplication a' has initializer but incomplete type
QApplication a(argc, argv);
^
C:\ \Documents\111\main.cpp:11: warning: control reaches end of non-void function [-Wreturn-type]
}
^
I am not sure what happened, yet seems like some setups were messed up.
QApplication is included, and not missing in the script.
111.pro
# Project created by QtCreator 2018-02-23T01:36:28
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = 111
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainview.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
It seems to me that this issue appeared after trying to run qt5.6_src.zip examples from https://en.ids-imaging.com/open-source.html.
Without completed code, I guess you need to add #include <QApplication> to main.cpp
The error message told you what is missing.
According to Qt's docs, the constructor's signature is QApplication(int &argc, char **argv).
Therefore, if you inherit from QApplication then the subclass's constructor must pass argc by reference. From your description, it appears that the constructor of your subclass is actually passing argc by value (i.e., int qMain(int, char**) ). That will cause some problems.
The issue is fixed by deleting the Qt folder and QtCreator folder in the <drive>:\Users\<username>\AppData\Roaming\QtProject and <drive>:\Users\<username>\AppData\Roaming\Qt. It stored incorrect settings, which I somehow setup by running open source scripts. For more information visit Where does QtCreator save its settings?.
I am trying to use Taglib with Qt5.7. But my programm crashes:
The GDB process terminated unexpectedly (exit code 0).
Cannot continue debugged process: The program is not being run.
During startup program exited with code 0xc0000135
There did not seem to be any error messages while building Taglib.
*.pro file
QT += core
QT -= gui
CONFIG += c++11
TARGET = untitled2
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
TAGLIBDIR = $$quote(D:/D/Programmieren/Libraries/taglib)
INCLUDEPATH += $$quote( $${TAGLIBDIR}/include )
LIBS += -L$$quote($${TAGLIBDIR}/lib) -ltag
main.cpp
#include <QCoreApplication>
#include <taglib/tag.h>
#include <taglib/fileref.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
TagLib::FileRef ref("D:/D/Media/Musik/Disturbed/The Sickness/Disturbed - Stupify.mp3");
return a.exec();
}
Edit:
I created Taglib-buildfiles using CMake-GUI and native MinGW-Installation since I did not manage to create them using Qt. My OS is Windows 10 x64 Education and I use Qt-Creator. I downloaded the latest Taglib-Release (1.11.1)
Why I cant create buildfiles using CMake:
First some *dll-files where missing, i coud solve that by just copying the ones from native MinGW-Installation to QT-MinGW.
Second I could not find any of the *exe-files desired by CMake so i could not change the path from native MinGW-Installation.
After rebuilding Taglib in debugmode I get this errors:
main.cpp:10: error: undefined reference to `_imp___ZN6TagLib8FileNameC1EPKc'
main.cpp:10: error: undefined reference to `_imp___ZN6TagLib7FileRefC1ENS_8FileNameEbNS_15AudioProperties9ReadStyleE'
main.cpp:11: error: undefined reference to `_imp___ZNK6TagLib7FileRef3tagEv'
main.cpp:11: error: undefined reference to `_imp___ZNK6TagLib6String9toCStringEb'
main.cpp:11: error: undefined reference to `_imp___ZN6TagLib6StringD1Ev'
main.cpp:10: error: undefined reference to `_imp___ZN6TagLib7FileRefD1Ev'
main.cpp:11: error: undefined reference to `_imp___ZN6TagLib6StringD1Ev'
main.cpp:10: error: undefined reference to `_imp___ZN6TagLib7FileRefD1Ev'
collect2.exe:-1: error: error: ld returned 1 exit status
Solved it by using new version (5.8 instead of 5.7) of Qt.
I've tried to compile the following code using Qt(4.6.3) + MinGW:
#include <QtCore/QCoreApplication>
#include <exception>
int main(int argc, char *argv[])
{
throw std::runtime_error("");
QCoreApplication a(argc, argv);
return a.exec();
}
... and got this error:
..\untitled11\main.cpp:6: error: 'runtime_error' is not a member of 'std'
Project created from scratch(console application), the pro file:
QT += core
QT -= gui
TARGET = untitled11
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
Tried to compile this using Qt+MSVC2008 compiler - works fine.
This is a standard exception, have no idea why is missing.
<exception> defines only the base std::exceptionclass; if you want child classes like std::runtime_error, you must include the <stdexcept> header.