Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. emit Qserialport.readyread in qml

emit Qserialport.readyread in qml

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 937 Views 1 Watching
  • 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.
  • P Offline
    P Offline
    Phong
    wrote on last edited by
    #1

    Hi all,

    I used to use qserialport in c++, and the easy way to read the data from serial is connected readyread with
    my custom read slot function.

    Recently, I tried to use qml for ui design, this is the reference I used : qcsvlog
    In his source code, he use timer to monitor and read the data per time, it works ok.

    But, I really wonder is there a way to use readyread in qml??
    and I found I CAN'T create a c++ signal and used it in qml....
    Lots of tutorials are talking about qml signal --> cpp Slot, but the opposite one.

    J.HilkJ 1 Reply Last reply
    0
    • P Phong

      Hi all,

      I used to use qserialport in c++, and the easy way to read the data from serial is connected readyread with
      my custom read slot function.

      Recently, I tried to use qml for ui design, this is the reference I used : qcsvlog
      In his source code, he use timer to monitor and read the data per time, it works ok.

      But, I really wonder is there a way to use readyread in qml??
      and I found I CAN'T create a c++ signal and used it in qml....
      Lots of tutorials are talking about qml signal --> cpp Slot, but the opposite one.

      J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #2

      @Phong there are Examples in both ways, even in the official docu.

      Here's a broken down example of my own:

      /*Cpp.Source File*/
      // connect our C++ signal to our QML slot
      // NOTE: if we want to pass an parameter to our QML slot, it has to be a QVariant.
          QObject::connect(this, SIGNAL(setText(QVariant)),
                               qmlObject, SLOT(setText(QVariant)));
      
      /*QML-File*/
      // this function is our QML slot
          function setText(text){
              console.log(text)
          }
      
      //Now call your QML SLot by emiting the signal
      ...
      emit setText("Hello From C++");
      ...
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      1
      • P Offline
        P Offline
        Phong
        wrote on last edited by
        #3

        Hi @J-Hilk

        Thanks for ur answer, your answer is correct.

        I have to apologized I didn't write my question clearly,
        I actually want to access C++ signal in qml and act the C++ Slot or qml Slot
        That is, do everything in qml.

        I finally found the solution on Qt Forum,
        I can write a signal in my C++ class

        signal : 
            void readyRead_();
        

        and call the signal in qml by adding "on" as prefix:

        MySerialPort {
                onReadyRead_(){
                //do sometihing
            }
        }
        

        Anyway, Thanks a lot!

        1 Reply Last reply
        1

        • Login

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