Results 1 to 7 of 7

Thread: how do i pass an parameter to setFilter() through a variable

  1. #1
    Join Date
    Feb 2006
    Posts
    9
    Qt products
    Qt3
    Platforms
    Unix/X11

    Angry how do i pass an parameter to setFilter() through a variable

    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
    Last edited by babusunlux; 3rd April 2006 at 12:20.

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: how do i pass an parameter to setFilter() through a variable

    If i have understood you need something like that code for convert string into const char *
    Qt Code:
    1. QString Vname="1AE01A"
    2. setFilter(Vname.data());
    To copy to clipboard, switch view to plain text mode 
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Feb 2006
    Posts
    9
    Qt products
    Qt3
    Platforms
    Unix/X11

    Angry Re: how do i pass an parameter to setFilter() through a variable

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: how do i pass an parameter to setFilter() through a variable

    Hmm yes i missed that...i m actual not really understand your problem but i think you need something like that
    Qt Code:
    1. QString str = "Columname = \"fieldvalue\"";
    2. setFilter(str.data());
    To copy to clipboard, switch view to plain text mode 
    a life without programming is like an empty bottle

  5. #5
    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: how do i pass an parameter to setFilter() through a variable

    You have to construct the contents of the variable yourself, for example by processing input from the user (for example from QLineEdit widget).

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how do i pass an parameter to setFilter() through a variable

    There's everything in the docs, all you need is to read them.
    Qt Code:
    1. setFilter( QString("ChName = \"%1\"").arg( Vname ) );
    2. // or
    3. setFilter( "ChName = \"" + Vname + "\"" );
    To copy to clipboard, switch view to plain text mode 

  7. The following 2 users say thank you to jacek for this useful post:

    ahmetturan (3rd July 2011), Nex (4th April 2007)

  8. #7
    Join Date
    Feb 2006
    Posts
    9
    Qt products
    Qt3
    Platforms
    Unix/X11

    Talking Re: how do i pass an parameter to setFilter() through a variable

    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

Similar Threads

  1. Pass variable from a form to another form
    By dark1988 in forum Qt Programming
    Replies: 5
    Last Post: 8th February 2011, 18:19
  2. nmake error during .pro compiling
    By mattia in forum Installation and Deployment
    Replies: 5
    Last Post: 18th June 2008, 10:15
  3. pass "this" as parameter
    By incapacitant in forum Newbie
    Replies: 17
    Last Post: 25th May 2006, 09:41

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.