Introduction to Qt/QML (Part 46) - Exporting Values from C++ to QML

preview_player
Показать описание
Welcome to module number eight of our "Introduction to QML" video series. In this module we'll use the knowledge that we gained in module 7 (remember it? QObject, signals, slots, properties, variants) in order to make C++ and QML talk to each other. In this first video, we are going to show how we can export objects of value classes (numbers, strings, etc.) from C++ to QML.

About the host:
This video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Рекомендации по теме
Комментарии
Автор

Your presentations are precise and also complete. It helped me to understand the concepts quickly. Great presentations

shahidasheik
Автор

Hey Jesper! You are not alone with the inspector Gadget .. the name it is evoking great memories from childhood .. when we were kids, my brothers and I viewed Inspector Gadget and others as Agent 86 (Maxwell Smart) ..

huveja
Автор

So cool, thanks so much for all these videos. You've enlightened a little French guy who was completely lost with the QML ;)

florianfeuillepain
Автор

Hey Jesper, thank you for the all tutorials, without that I would spend much much more time to learn it, because the official docu is not very good for beginners. I wachted all this videos until that and I will watch the remaining videos too, they are really helpful.
I have one question. I would like to bring my object from c++ globally to qml and found the appraoch with QuickView and QQmlContent the best. But I have only one window in my application where I would like to use object Window for setting properties like minimal width and height, etc. But QuickView does not support Window. Without Windows when I change the size of the window the objects inside does not resize. Would you have any ideas how to do it?
Frank

frantisekprinz
Автор

No information no examples shared for SetContextProperty in hierarchy of Contexts.
What about to remove properties from Contexts. ?
How to use different context in Qml ?

badassopenpolling
Автор

Hello Jesper and KDBA team! I have a question and I feel like the dumbest out there for asking a simple question. What I understand is that we create a QML project as we did before in the tutorial. We get automatically created main.cpp file apart from qml file.
In that main.cpp we write the code to make qml be able read our defined values in cpp.

Now, when I open main.cpp I have following:
int main(int argc, char *argv[])
{

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)

#endif
QGuiApplication app(argc, argv);



QQmlApplicationEngine engine;
const QUrl
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);

return app.exec();

}


Then, I tried to implement what you teach in this video, and I added these lines :
QQmlContext* context = engine.rootContext();
context->setContextProperty("_aString", QString("Hello Friend"));
context->setContextProperty("_aSize", QSize(800, 600));

As I have QQmlApplicationEngine engine already I am not using QQuickView (which I tried though with errors :D)
However, when I run everything it seems to work fine but QT gives me a warning:
qrc:/main.qml:21: ReferenceError: _aString is not defined

This error message comes even though the app runs fine. I used a label with that _aString value and it shows correctly?! Is it ok? and am I doing things correctly?

Thank you!

Arsbars
Автор

How is QML notified when the QQmlPropertyMap is updated ? I cannot see any signal that can be used by the QML to notify it of an update ?

SimonPlatten
Автор

Hey Jesper, how do I create a ListView model from a QList of a custom class that inherits QObject. Please help.

agnirulez
Автор

I'm a beginner to Qt and programming in general. I encountered error ...I want to send string from qt to qml....

madanmohanathmakuru
Автор

I also think about Inspector Gadget :v
We are not alone

electruc
welcome to shbcf.ru