emit Qserialport.readyread in qml

  • 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.

  • @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)));
    // this function is our QML slot
        function setText(text){
    //Now call your QML SLot by emiting the signal
    emit setText("Hello From C++");

  • 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 {
            //do sometihing

    Anyway, Thanks a lot!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.