I want to check the communication status with a color blinking or label.
-
Hello, I'm a new Qt developer.
I'm asking this question because I want to check if the communication is smooth for PCs with DB servers.
Here's how I thought of it
If the DB server and the PC with the QT program are communicating well, the green light comes on, and if the communication is not smooth, the red light comes on. Green light and red light are images. We're thinking about a minute apart when we're sending and receiving signals. I searched on the Internet and found that there were some examples that I thought of, but I couldn't apply them.
I just drew it up.
It's like this. When the signal goes back and forth, the red light disappears
It's how the red light comes on and the green light disappears when the signal doesn't go smoothly.
Is there a good example or code example?
The method is TCP/IP. I'm thinking of using QTcpsocket.
-
@meria0503 It is not really clear what you are asking.
You can hide a widget calling hide() on it and you can show it again calling show() on it. So that is what you could do. Or use only one widget (QLabel) to show the image and simply show the one (red or green) which is needed to show the state. -
The content is a little strange because the translation is not smooth.
To be exact, when you communicate with the server and the client,
I'm thinking about how the green light turns on if it's normal, and the red light turns on if it's defective.
I want to implement this.
-
@meria0503 So, you are asking how to decide whether you need to show red or green light?
Well, I do not know what your requirements are. For example if connection breaks you switch to red light. But you have to specify what "defective" means for you. -
@jsulm The reason why I need it is that I receive data from the server where DB is located, but if the connection is disconnected, I cannot receive the data, so I need to know the contents
It doesn't matter if it's not that green light or red light, it doesn't matter if it's a text message of connect and disconnect.
-
@meria0503 Do you use https://doc.qt.io/qt-6/qtsql-index.html ? You can set red light when your SQL queries fail.