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
    18
    Thanks
    2
    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
    18
    Thanks
    2
    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 received on other forum for Qt.



    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. Share serial port between two programs on Windows
    By RazZziel in forum Qt Programming
    Replies: 4
    Last Post: 20th July 2017, 13:06
  2. Replies: 5
    Last Post: 13th January 2014, 09:24
  3. Replies: 5
    Last Post: 27th July 2012, 07:21
  4. Replies: 1
    Last Post: 20th January 2012, 04:39
  5. Replies: 4
    Last Post: 26th June 2007, 19:19

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.