PDA

View Full Version : how do i pass an parameter to setFilter() through a variable



babusunlux
3rd April 2006, 12:17
hai

I am using QDataTable to display the data from the database with three fields which has the following data types.
Channel Name as char, Chval as int and GenDateTime as datetime in mysql, i have set the database connection and the data has been displayed in the qdatatable, but i want to set the setfilter() so the i am can apply the where option.

If i pass the the value directly in the is format setFilter("ChName=\"1AE01A\"") it works fine but how do i pass through some variable.
Say QString Vname="1AE01A"
setFilter("ChName =......?......");

But not with QString i need to give on GenDateTime column where i am interested in retreiveing the records which 3 days less than current date and time. And also how do i get 3 days back date time from current date time.

Can anybody help me .......... Which will be very help ful..

Thank you
Babu

zlatko
3rd April 2006, 13:20
If i have understood you need something like that code for convert string into const char *


QString Vname="1AE01A"
setFilter(Vname.data());

babusunlux
3rd April 2006, 13:40
Thanks for ur interest.

But if i use Variable name.value() where do i specify the column name of a table. Generally if like to give the direct value this is the way i give i.e,
setFilter("Columname = \"fieldvalue\"");
Which works fine, but ur answer talks about only the fieldvalue can u help me to over come this problem. I am a beginner in QT. Please.....

Thank you
Babu

zlatko
3rd April 2006, 14:02
Hmm yes i missed that...i m actual not really understand your problem but i think you need something like that


QString str = "Columname = \"fieldvalue\"";
setFilter(str.data());

wysota
3rd April 2006, 14:02
You have to construct the contents of the variable yourself, for example by processing input from the user (for example from QLineEdit widget).

jacek
3rd April 2006, 17:13
There's everything in the docs, all you need is to read them.

setFilter( QString("ChName = \"%1\"").arg( Vname ) );
// or
setFilter( "ChName = \"" + Vname + "\"" );

babusunlux
4th April 2006, 07:13
Thank's Jacek

I think i have got the right answer i have not yet added in the code i thought let me tell thanks to u first. I think it should work for me .

Thanks......... Very Much