Results 1 to 3 of 3

Thread: Run a slot only it has received x number of signals

  1. #1
    Join Date
    Jun 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Run a slot only it has received x number of signals

    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.

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Run a slot only it has received x number of signals

    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.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Run a slot only it has received x number of signals

    Quote Originally Posted by arortell View Post
    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,
    _

Similar Threads

  1. Replies: 2
    Last Post: 15th November 2014, 13:45
  2. Replies: 1
    Last Post: 15th January 2013, 19:08
  3. Qt 4.7 limit on number of signals?
    By rghosh in forum Qt Programming
    Replies: 2
    Last Post: 9th February 2011, 10:32
  4. QThread Signal Not Received By Main Thread Slot
    By EF2008 in forum Qt Programming
    Replies: 7
    Last Post: 4th June 2010, 08:06
  5. Wierd debug signals received while aborting QHttp/QFtp
    By codeslicer in forum Qt Programming
    Replies: 5
    Last Post: 30th May 2009, 01:02

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.