PDA

View Full Version : How to share Serial port opened in Main Window class with Dialog box class



saurabh162
31st July 2018, 08:34
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

ado130
31st July 2018, 13:05
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.

saurabh162
8th August 2018, 16:00
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 :)

d_stranz
8th August 2018, 16:40
I have read main disadvantages of using signal and slot approach for returning values.


And where did you read this misinformation?