Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

sending cmd to serial and tcpip depending on what is connected



  • Hi

    • I have 2 panels Serial port and Tcpip on the first TAB of a GUI.

    • GUI communicates with Hardware with serial port panel or Tcpip which can be selected using a radio button option.

    • serial port panel has its own backhand c++ files for detecting serial ports , read , write etc

    • same with tcpip.

    • both work well independently.

    0_1535463523494_cb29b0cc-3432-4b4c-bef7-ba9690fe0b91-image.png .

    0_1535463570823_ce87fc35-3d02-492c-bce4-fc094034770f-image.png

    both serial and tcp are defined as

    QQmlContext *classContext = engine.rootContext();
    classContext->setContextProperty("cpp_serial", &connect_serial_port);
    classContext->setContextProperty("cpp_tcp", &tcp); 
    

    in main.cpp

    Problem:

    1.) I need a wrapper on top of serial and tcp called cmd_do which checks the which panel (serial or tcpip is connected) and send cmd to that particular connection type.
    2.) how do it read the radio button status or property in c++.
    3.) if I define a class cmd_do which uses other classes like serial and tcpip which i have defined for the two panels mentioned above.

    Regards
    Prasad



  • hi,
    @Prasad_Socionext said in sending cmd to serial and tcpip depending on what is connected:

    2.) how do it read the radio button status or property in c++.

    One possible solution is to have a Q_PROPERTY bool in your 2 classes

    exemple :

    Q_PROPERTY(bool isSelected READ isSelected WRITE setIsSelected NOTIFY isSelectedChanged)
    

    then in qml :

      RadioButton {
                text: "serial"
                onClicked : cpp_serial.isSelected=checked
            }
    

Log in to reply