PDA

View Full Version : Run a slot only it has received x number of signals



arortell
23rd June 2016, 21:08
Hello I am very new to QT here. I am just playing with QT5 with QSql here. This is my first QT GUI application. What I am doing is creating a simple form to connect to a MySQL database and run a query on it. I have it displaying the results in a QTableView. I get the input from the user in 5 QLineEdits (one is database server which in my case is just 127.0.0.1, another is the user, password, database name and one is the query string). The query is run from a clicked signal from a QPushButton. What I want to do is have the database connection created as soon as the first 4 QLineEdits have been filled in "all but the query string" so it is already connected before the run button is clicked to run the query. So my question is: is it possible to have a slot called only after it has received x amount of signals "4 in this case". Thank you for your help.

jefftee
24th June 2016, 02:01
Not possible to do what you suggest, however, if I were going to design this, I would disable the push button to execute the query (and I presume complete the dialog) until the line edit containing the query passed validation, which in this case would require that all 5 line edits contained valid values.

You could also test for successful database connection when any of the line edits send the QLineEdit::editingFinished signal (or any of the other QLineEdit signals if you prefer). If the connection is successful, enable to OK button or whatever button you use to complete the dialog. If the connection fails, then leave the button disabled and cancel is the only option, etc.

Alternatively, provide a "Test" pushbutton that you use to test the connection, etc.

Lots of ways to accomplish what you want without having to do something like count signals, etc.

Good luck.

anda_skoa
24th June 2016, 10:36
So my question is: is it possible to have a slot called only after it has received x amount of signals "4 in this case".
Even if this were possible, which it isn't as jefftee already explained, it is not something you would want in this situation.

Because your criteria is not how many signals have been emitted but which values you have.
If only the first field would get a value 4 times that would satisfy the "4 signals" but you would only have one out of four required parameters.

So follow jefftee's advice: one slot connected to all four line edits and in that slot retrieve all four values and then decide if they are sufficient to attempt a connect

Cheers,
_