PDA

View Full Version : SQL queries and slots



fnmblot
20th April 2007, 02:53
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:


//First Push Button Clicked
connect(ui.firstPB, SIGNAL(clicked()), this, SLOT(clearTextDateFields()));
connect(ui.firstPB, SIGNAL(clicked()), this, SLOT(pieceQuerySlot()));
connect(ui.firstPB, SIGNAL(clicked()), this, SLOT(firstPBSlot()));
connect(ui.firstPB, SIGNAL(clicked()), this, SLOT(setFormValues()));
connect(ui.firstPB, SIGNAL(clicked()), this, SLOT(navPBCheck()));

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

wysota
20th April 2007, 07:33
Connect to a single custom slot which simply calls the five methods you want to execute.

fnmblot
20th April 2007, 14:58
You mean something like this?

connect(ui.firstPB, SIGNAL(clicked()), this, SLOT(firstPBSlot()));

and then have


void nnDBSPieceViewForm::firstPBSlot()
{
clearTextDateFields();
pieceQuerySlot();
changeEntryByUID();
setFormValues();
navPBCheck();
}

wysota
20th April 2007, 18:20
Yes, something like that.

fnmblot
23rd April 2007, 21:19
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

wysota
23rd April 2007, 22:06
If you're lazy then: QInputDialog.

parmanax
24th April 2007, 00:03
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

fnmblot
24th April 2007, 18:42
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

parmanax
26th April 2007, 02:20
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