Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How To C++ output to QML Text Element
QtWS25 Last Chance

How To C++ output to QML Text Element

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.5k Views
  • 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 Offline
    A Offline
    alfalive
    wrote on last edited by
    #1

    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
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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
      0
      • A Offline
        A Offline
        alfalive
        wrote on last edited by
        #3

        Thank you.
        I am now one step further.

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          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
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved