Undefined reference to QDeclarativePropertyMap in qt - c++

I am new to Qt.
Qml is facing issue while passing QDeclarativePropertyMap from c++ to Qml.
Here is my code:
main.cpp
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QtDeclarative/qdeclarativepropertymap.h>
#include <QVariant>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQmlApplicationEngine engine;
///giving error in below line
QDeclarativePropertyMap *m_propertymap = new QDeclarativePropertyMap();
m_propertymap->insert("time" ,QVariant(QString("yet to do")));
m_propertymap->insert("area" ,QVariant(QString("india")));
engine.rootContext()->setContextProperty("M_propertymap", m_propertymap);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
Error:
undefined reference to QDeclarativePropertyMap QObject

Use QtQml/QQmlPropertyMap instead
undefined reference to QDeclarativePropertyMap QObject
is a linker error, cause you trying to mix different versions of qtquick

Related

Using QT; QWidget: Must construct a QApplication before a QWidget

I am using vtk QT, i've installed VTK, PCL libraries well, after run the project the realese mode; i found the following error.
QWidget: Must construct a QApplication before a QWidget
As the error message says, you will need to create a QApplication before you can instantiate and use a QWidget. For example:
#include <QApplication>
#include <QDialog>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QDialog dialog;
dialog.setModal(true);
dialog.show();
return app.exec();
}

I am unable to reference QSettings using Qt

I am running a project that uses Qt. I have installed version 5.10.1 (msvc2017_64). I receive an error that the QSettings is undefined. I cannot find the reference in the libraries installed.
#include "mainwindow.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QCoreApplication::setApplicationName("Circuit Editor");
QSettings settings;
MainWindow w;
w.setWindowTitle("Circuit Editor");
w.show();
return a.exec();
}
My two cents:
1) You forgot to include the header:
#include <QSettings>
2) You declared a QSetting object but you are not doing anything with it. Is that what you want to do?
Never use #include <QtModule/QClass> format of includes. They hide project misconfiguration. Use #include <QClass> instead.
If you're unsure of what to include, include the entire module and deal with details later: #include <QtModule>.
Thus:
#include "mainwindow.h"
#if 1
// entire module
#include <QtWidgets>
#else
// needed classes
#include <QApplication>
#include <QSettings>
#endif
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QCoreApplication::setApplicationName("Circuit Editor");
QSettings settings;
MainWindow w;
w.setWindowTitle("Circuit Editor");
w.show();
return a.exec();
}

Signal and Slot between QML and c++

my problem is, that I can't get a signal and slot connections between a cpp and a qml file.
First of all I've found some solutions in the web, but it doesn't work.
I'm sure, that the mistake is mine, but I didn't find it.
main.cpp:
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickWindow>
#include <QQmlContext>
#include "Hotfolder.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QScopedPointer<cReadJson> jsonReader(new cReadJson);
QScopedPointer<cHotfolder> hotfolder(new cHotfolder);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
engine.rootContext()->setContextProperty("jsonReader", jsonReader.data());
engine.rootContext()->setContextProperty("hotfolder", hotfolder.data());
QObject *topLevel = engine.rootObjects().at(0);
QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
QObject::connect(&cHotfolder, SIGNAL(sigNewOrder()), window, SLOT(
// Here is the mistake, that I can't find the Slot in QML
return app.exec();
}
This is my main.cpp file. In this file I found the Signal from the cpp file, but not the Slot in QML.
main.qml:
function bla()
{
console.log("bla")
}
This is the function in my main.qml file.
So where ist mistake?
Many thanks in advance!
Ben
The solution is:
Just connect to the signal from within QML and not from C++
example:
Component.onCompleted: hotfolder.sigNewOrder.connect(bla)

C++:QX11EmbedContainer not working on Qt

Given below is the code that I have written for opening VLC from Qt. I want to use the QX11EmbedContainer so that I can use it to "contain" VLC.
#include "mainwindow.h"
#include <QApplication>
#include <QProcess>
#include <QX11EmbedContainer>
using namespace std;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString prog="C:/Users/Administrator/Desktop/... .exe";
QProcess *proc=new QProcess();
proc->start(prog);
return a.exec();
}
On adding the header file QX11EmbedContainer I get the following error:
C:\Users\Administrator\Documents\HA\main.cpp:4: error: C1083: Cannot open include file: 'QX11EmbedContainer': No such file or directory
Is QX11EmbedContainer an add-on? If not then where am I going wrong?

Can't register C++ type to QML system

I'm trying to add C++ type to QML system.
#include <QtGui/QGuiApplication>
#include <QDeclarativeEngine>
#include <QDeclarativeComponent>
#include "qtquick2applicationviewer.h"
#include <QQmlApplicationEngine>
class FooBar: public QObject {
Q_OBJECT
};
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine("qml/RBot/main.qml");
qmlRegisterType<FooBar>("io.secorp", 1, 0, "FooBar");
return app.exec();
}
But when I'm trying compile this(i don't import this in .qml file, only testing) I'm geting errors about debugging.
What's wrong?
Thanks.
You're mixing Qt Quick 1 and 2, which is unsupported. The QDeclarative headers are for Quick 1 and the QQml headers are for Quick 2.
Your includes should be:
#include <QtGui/QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlComponent>
#include "qtquick2applicationviewer.h"
#include "foobar.h"
The definition of FooBar should be in its own header, and QObject should be included there for moc to work its magic.
For more details, see this already reported bug in Qt:
QTBUG-32138 - Hello World for QtQuick2 does not compile with #include when QML debugging is on