Qt first project
-
Hi, thank you. And which part of Blocking Master Example code do I choose to put inside the brackets of button released?
-
@nick784512
The part you want to call when button is pushed.
In the sample, Dialog.cpp is the window. There is no UI file.It calls
void Dialog::transaction()But the real work in done is MasterThread.
So you cannot just put it into the button click.If you are trying something simple,
this sample is maybe a bit complex to start with
using a thread with more.To just open a comport and write "start", all you need it.
(Note. you should add more error checking code.)so if you put in slot
QSerialPort serial; serial.setPortName("com1"); serial.open(QIODevice::ReadWrite); serial.setBaudRate(QSerialPort::Baud115200); // MAKE SURE ITS CORRECT serial.setDataBits(QSerialPort::Data8); // MAKE SURE ITS CORRECT serial.setParity(QSerialPort::NoParity); // MAKE SURE ITS CORRECT serial.setStopBits(QSerialPort::OneStop); // MAKE SURE ITS CORRECT serial.setFlowControl(QSerialPort::HardwareControl); // MAKE SURE ITS CORRECT if (serial.isOpen() && serial.isWritable()) { qDebug() << "Serial is open"; output = "START"; serial.write(output); serial.waitForBytesWritten(1000); qDebug() << "sent"; }
if you need a design where "the other end" answers, QSerialPort serial should live as member
of mainwindow.Btw:
this sample
http://doc.qt.io/qt-5/qtserialport-terminal-example.html
Can send text and show what comes back. its super for testing. -
Thank you. What version of C++ does the Qt use? It is the "classic" C++ or C++11?
-
@nick784512
Both. I think from 5.7 it must be c++11 but 5.6 LTS can be build with pre c++11.
https://blog.qt.io/blog/2015/12/18/introducing-long-term-support/ -
Hello, Can someone send me a Qt program with one button that when I press it, it sends the command "START" through COM ? I am trying to figure out from Qt examples, but the more I read the more I am confused.
-
Hi,
What exactly is confusing you ?
-
The "terminal" example has so many functions, but too little explanation. How am I supposed to learn how it works, and what functions to use in my simple program (see above)?
-
Do you mean explanation are missing from here ?
-
If you try to read all the files ( that are below )of the example, the explanation is too little.
-
Too little about what ? The key functions are explained in the presentation page and the rest is rather nicely written. So please be more specific about which part is giving you a hard time.
-
What this http://doc.qt.io/qt-5/qtserialport-terminal-settingsdialog-cpp.html code does?
From C language I know that we have to also call a function. Where are the functions called? -
The dialog is shown when clicking on the configure button in main dialog.
Then when you click on the connect button, the openSerialPort method will retrieve the current setting for the serial port and update the
serial
member variable properties with the settings from the dialog. -
Thank you. Now that I want to make the simple project as I said before. How many files do I need?
mainwindow.h
mainwindow.cpp
main.cpp
mainwindow.uiare all these enough?
-
Based on your requirements, you only need a QWidget, a QPushButton and a QVBoxLayout to put the button nicely in the widget.
-
But where will I put the code?
-
In your QWidget subclass.
-
In main.cpp?
-
@nick784512 I would suggest you to create a simple widgets application and play a bit with it. You will see how Qt widgets applications are usually implemented. See http://doc.qt.io/qtcreator/creator-writing-program.html
Asking others to send you an implementation is not really the right way to learn. Best is "learning by doing" and asking specific questions if you're stuck. -
I have tried this one: https://www.youtube.com/watch?v=UD78xyKbrfk
and I connected the arduino to the COM3 with a program that sends 2 3 2 3... but the Qt program does not display the 2 3 2 3 .... -
@nick784512
In that video, he mere set the text he gets to a QLabel
MainWindow::serialReceived .
If it should respond to anything you must program it yourself.Please show what you changed it into to reply ? :)