QML import rcc modules - qt

I try to create an application in which I use rcc modules but I get the error "modules not installed".
I have the following folders and files:
MainFolder
|_Folder1
|_Folder11
|_qmldir
|_MyButton.qml
|_Folder2
|_qmldir
|_MyComponent.qml
Application
|_application.pro
|_main.cpp
|_main.qml
|_rccFolders
|_folder11.rcc
|_folder2.rcc
My qmldirs contain:
In Folder11:
module MainFolder.Folder1.Folder11
MyButton 1.0 MyButton.qml
In Folder2:
module MainFolder.Folder2
MyComponent 1.0 MyComponent.qml
The main.cpp:
#include ...
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QString sourcePath="C:/path_to_rcc_files/";
QQmlApplicationEngine engine;
QResource::registerResource(sourcePath+"folder11.rcc");
QResource::registerResource(sourcePath+"folder2.rcc");
engine.addImportPath(":/"); //to use .rcc files
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
The main.qml:
//QML imports
import MainFolder.Folder1.Folder11
import MainFolder.Folder2
ApplicationWindow
{
...
}
But when I execute the application, I get:
qrc:/main.qml:... module "MainFolder.Folder1.Folder11" is not installed
qrc:/main.qml:... module "MainFolder.Folder2" is not installed
What is wrong in my code? Thanks.

You may debug resource problems (go to Debugging section at the end) using QML_IMPORT_TRACE
It says import <ModuleIdentifier> <Version.Number> [as <Qualifier>] so be sure to try:
import MainFolder.Folder1.Folder11.MyButton 1.0
import MainFolder.Folder2.MyComponent 1.0

Maybe you could try to use an import path with qrc: prefix:
engine.addImportPath("qrc:/");
I am not completely sure (and actually the documentation says both the :/ and qrc:/ notations should work), but I remember I had some similar issues in the past. At least in my apps (where I use a similar structure) I always use the qrc:/ prefix.

Related

qcleanlooksstyle belongs to which QT += in Qt

I am searching "QCleanlooksStyle" belongs to which "QT +=". please help, ive centos 6.4 and Qt 5.3.
#include <QApplication>
#include <QCleanlooksStyle>
#include <QtWidgets>
#include "buttonbox.h"
int main( int argc, char **argv )
{
QApplication app( argc, argv );
app.setStyle( new QCleanlooksStyle );
ButtonBoxDialog dlg;
dlg.show();
return app.exec();
}
According to the docs:
QMotifStyle, QPlastiqueStyle, QCleanlooksStyle, and QCDEStyle are
replaced with a new fusion style. If your application depends on any
of these removed styles, you can either use the qtstyleplugins project
to get these styles or update your application to use the new fusion
style. For more details about this change, see
https://blog.qt.io/blog/2012/10/30/cleaning-up-styles-in-qt5-and-adding-fusion/.
So you must clone the project, compile it and install it:
git clone git://code.qt.io/qt/qtstyleplugins.git
cd qtstyleplugins/
qmake
make
sudo make install
Then you must set the style using the following (you should not modify the .pro):
app.setStyle("cleanlooks");

how to debug virtual variable translator.load()

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);
}

A new Qt widget application will not compile

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?.

qt creator : no such a file or directory

hi i'm just trying to compile an easy project in qt
#include <QApplication>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton bouton("Salut les ZĂ©ros, la forme ?");
bouton.show();
return app.exec();
}
but i have this error : /home/eid/test/easyprojet/main.cpp:1: error: QApplication: No such file or directory
can anyone help me ?
sorry for my english
In Qt5, it resides in , while in Qt4 it was .
In Qt5 you need to add QT += widgets to your .pro file.
It may be also because the project is not in the workspace of QT creator.
It happened with me before.
so,try to put the project in the workspace .

QT3 linker errors after switching to another compiler

I have created simple test project that uses QT3 gui. The main function is as follows:
int main(int argc, char** argv)
{
QApplication a(atgc, argv);
MainWindow *w = new MainWindow;
w->show();
a.setMainWidget(w);
a.exec();
if(w) delete w;
return 0;
}
When I compile it like this:
qmake
make
it is ok (the used compiler is g++-2.95.4). But when I do this:
qmake
make CXX=g++-3.3.6 LINK=g++-3.3.6
I get tons of link errors like this:
.obj/main.o(.text+0x27): In function `main':
: undefined reference to `QApplication::QApplication[in-charge](int&, char**)'
.obj/main.o(.text+0x66): In function `main':
: undefined reference to `QApplication::setMainWidget(QWidget*)'
.obj/main.o(.text+0x6e): In function `main':
: undefined reference to `QApplication::exec()'
It seems like it has not linked qt libraries properly. Is there any idea how to build project using any other compiler? I am using linux RedHat.

Resources