Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    How To C++ output to QML Text Element

    General and Desktop
    2
    4
    1270
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      alfalive last edited by

      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":https://drive.google.com/folderview?id=0B5fK4Qk7cdfnQmVweWgycktwSTA&usp=sharing

      1 Reply Last reply Reply Quote 0
      • dheerendra
        dheerendra Qt Champions 2022 last edited by

        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;
        view.setSource(QUrl("qrc:/app.qml"));
        QQmlEngine *eng = view.engine();
        QQmlContext *cont = eng->rootContext();
        MyTimer mTimer;
        cont->setContextProperty("MTimer",&mTimer);
        // Create an instance of my timer
        view.show();
        

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply Reply Quote 0
        • A
          alfalive last edited by

          Thank you.
          I am now one step further.

          1 Reply Last reply Reply Quote 0
          • dheerendra
            dheerendra Qt Champions 2022 last edited by

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

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            1 Reply Last reply Reply Quote 0
            • First post
              Last post