Results 1 to 9 of 9

Thread: SQL queries and slots

  1. #1
    Join Date
    Jul 2006
    Location
    Atlanta, GA
    Posts
    86
    Thanks
    26
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default SQL queries and slots

    Hey Everyone
    I have successfully created a frontend to a database application. In my View Form App, I have 4 buttons, First Prev Next Last. Each of these buttons runs about 200 lines of the same code. This seems very inefficient to me. Can anyone give me some suggestions to make it more efficient?

    I would like to have when a user clicks one of the buttons, 5 functions/slots called. The first slot would clear the form, then run the QSqlQuery, then choose which record to encapsulate, next populate the form with the values from the query, then Enable/Disable the 4 navigation buttons. The connectors currently look like this:

    Qt Code:
    1. //First Push Button Clicked
    2. connect(ui.firstPB, SIGNAL(clicked()), this, SLOT(clearTextDateFields()));
    3. connect(ui.firstPB, SIGNAL(clicked()), this, SLOT(pieceQuerySlot()));
    4. connect(ui.firstPB, SIGNAL(clicked()), this, SLOT(firstPBSlot()));
    5. connect(ui.firstPB, SIGNAL(clicked()), this, SLOT(setFormValues()));
    6. connect(ui.firstPB, SIGNAL(clicked()), this, SLOT(navPBCheck()));
    To copy to clipboard, switch view to plain text mode 

    I guess what I am asking, is how do I pass the query value from one slot to another?



    Thanks in advance, let me know if I am clear as mud

    fnmblot

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SQL queries and slots

    Connect to a single custom slot which simply calls the five methods you want to execute.

  3. #3
    Join Date
    Jul 2006
    Location
    Atlanta, GA
    Posts
    86
    Thanks
    26
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SQL queries and slots

    You mean something like this?
    Qt Code:
    1. connect(ui.firstPB, SIGNAL(clicked()), this, SLOT(firstPBSlot()));
    To copy to clipboard, switch view to plain text mode 

    and then have

    Qt Code:
    1. void nnDBSPieceViewForm::firstPBSlot()
    2. {
    3. clearTextDateFields();
    4. pieceQuerySlot();
    5. changeEntryByUID();
    6. setFormValues();
    7. navPBCheck();
    8. }
    To copy to clipboard, switch view to plain text mode 
    fnmblot
    --------------------------------------
    Gee Ricky, I'm sorry your mom blew up.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SQL queries and slots

    Yes, something like that.

  5. #5
    Join Date
    Jul 2006
    Location
    Atlanta, GA
    Posts
    86
    Thanks
    26
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Talking Re: SQL queries and slots

    Wow! Worked like a charm! I condensed 900 lines of code to 275. Now I just need to figure out how to create a login dialog prompt for my users to connect to the db and I will be complete and ready to put it out on kde-apps. Can anyone maybe direct me to a howto or some other open source code for this, please?

    Thanks in advance,

    fnmblot

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SQL queries and slots

    If you're lazy then: QInputDialog.

  7. #7
    Join Date
    Apr 2007
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: SQL queries and slots

    hi there fnmblot!

    did you implement the database in MySQL? I have created a mysql database and would like to write some kind of interface with qt? Any specific C++ windows interface to suggest? which did you use? can you send me some kind of sample code to get an idea how somthing like this can be implemented?

    thanx in advance!

    lara

  8. #8
    Join Date
    Jul 2006
    Location
    Atlanta, GA
    Posts
    86
    Thanks
    26
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SQL queries and slots

    Well, I am not really feeling lazy about it. I am currently looking at the sqlbrowser in the demos. But thanks for the suggestion.

    Parmanax, I will post my code here later today.

    fnmblot

  9. #9
    Join Date
    Apr 2007
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: SQL queries and slots

    Hi there,

    just to remind you to post your code if this is of no inconvenience to you. Would be really very nice to have it as a starting point to go. Thanks in advance!

    Lara

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.