How To C++ output to QML Text Element

  • In short: I tried several tutorials and can not find out how to send my 'cout' to an qml file Text element to change the text in it.

    For example

    Text {
    id: mytext
    text: "Hello"

    It shows a window with "Hello" text in it. And I want to change that text from cpp file to "Bye" for example.

    I tried to understand how Signals and Slots are working but most tutorials are either incompatible with my version of qt or to difficult to follow for me.

    I use:
    Ubuntu 14.04
    QtCreator 3.1.1
    Based on Qt 5.2.1 (GCC 4.8.2, 64 bit)
    Built on Jul 2 2014 at 11:57:41

    Here is my timer application from some tutorial running in terminal: "MyTimerTest":

  • Qt Champions 2017

    welcome to forum. Refer the Qt assistant for "Integrating QML to C++".

    1. In order to integrate with Qml and Qt you need to create the Qt Quick UI application.
    2. You need to expose the C++ Qobject to QML

    Qt Assistant has good Tutorial and examples. You should get them now.

    Just I have pasted sample of main.cpp here.

    QGuiApplication a(argc, argv);
    QQuickView view;
    QQmlEngine *eng = view.engine();
    QQmlContext *cont = eng->rootContext();
    MyTimer mTimer;
    // Create an instance of my timer;

  • Thank you.
    I am now one step further.

  • Qt Champions 2017

    If you need complete example drop an email to me. I will send the complete sample of the above.

Log in to reply