Results 1 to 2 of 2

Thread: How to share Serial port opened in Main Window class with Dialog box class

  1. #1
    Join Date
    Jun 2018
    Posts
    13
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default How to share Serial port opened in Main Window class with Dialog box class

    Dear Developers,

    In my Qt project I have two C++ classes named "MainWindow" and "DialogBox"

    I used serial port class object of QT to open a serial port in MainWindow class and now I want to send and receive data from "DialogBox" class using same serial port opened in MainWindow class.

    Please tell me what is correct approach to share same serial port object between MainWindow and DialogBox Class.


    Kindly inform me if you need any other information from me.

    Thank and Regards

    Saurabh Jain

  2. #2
    Join Date
    Jun 2018
    Posts
    13
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to share Serial port opened in Main Window class with Dialog box class

    This problem has been solved using following answer from other Qt forum


    You could use signal and slot instead of sharing the actual QSerial object.
    http://doc.qt.io/qt-5/signalsandslots.html
    So define new slots in Mainwindow that forms your interface the dialog would use.
    Like
    void SendCmd(QByteArray data);

    and in dialog ,
    define new signals for buttons to use
    void SendCmd(QByteArray data); ( yes same name as the slot in main)

    then hook up dialogs signals to mainwindows slot before u call exec() on dialog and
    then u can use serialport from dialog.
    by simply doing
    emit SendCmd(xxxx)

    in buttons click or where u need it.

    Alternatively, just add a parameter to the Dialogs constructor and pass the
    QSerialPort from mainwindow when you construct the Dialog.

Similar Threads

  1. Replies: 3
    Last Post: 8th August 2018, 16:40
  2. Replies: 2
    Last Post: 31st July 2018, 13:12
  3. How to share Serial port opened in Main Window class with Dialog box class
    By saurabh162 in forum Best Practices in Qt Programming
    Replies: 1
    Last Post: 31st July 2018, 10:46
  4. Replies: 5
    Last Post: 13th January 2014, 09:24
  5. Replies: 1
    Last Post: 20th January 2012, 04:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.