Results 1 to 4 of 4

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
    Jan 2017
    Posts
    58
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows

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

    I would suggest to pass the Serial port pointer to your DialogBox, e.g. in constructor.

    Also possible solution is to define SIGNAL and SLOT between your classes. In MW you can define slot sendData() and in DB signal sendData(). Then in MW you can define readyRead() signal and in DB readyRead() slot.
    Last edited by ado130; 31st July 2018 at 13:09.

  3. The following user says thank you to ado130 for this useful post:

    saurabh162 (8th August 2018)

  4. #3
    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

    Dear Developers,

    Above method work perfectly when I want to send serial port commands from Dialog box to Main Window.

    But I would be grateful to you, if you can please me how can I read data collected in mainwindow using array after sending serial command from Dialog box.

    I have asked this question because I have read main disadvantages of using signal and slot approach for returning values.


    Thank you

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,235
    Thanks
    303
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

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

    I have read main disadvantages of using signal and slot approach for returning values.
    And where did you read this misinformation?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 2
    Last Post: 31st July 2018, 13:12
  2. 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
  3. Share serial port between two programs on Windows
    By RazZziel in forum Qt Programming
    Replies: 4
    Last Post: 20th July 2017, 13:06
  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.