Results 1 to 7 of 7

Thread: QString function by value

  1. #1
    Join Date
    Nov 2010
    Posts
    14
    Qt products
    Qt4
    Platforms
    Windows

    Post QString function by value

    Newbie; the function below returns nothing(empty) but if I assign art="abc" returns abc what is wrong; please help.
    Thanks
    hmarani
    Qt Code:
    1. QString Dialog::forsuly()
    2. {
    3.  
    4. model.setQuery("SELECT * FROM art");
    5. QString artn = model.record(4).value("artln").toString();
    6. return artn
    7. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Lykurg; 23rd November 2010 at 21:12. Reason: missing [code] tags

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QString function by value

    Just some possible issues based on your code:

    • Your record index could be wrong (QSqlMode::record() returns an empty result if the index is wrong)
    • The value "artln" might not exist (should it be artn?). (QSqlRecord::value() returns an invalid variant if the value name doesn't exist)

    If necessary, check the results of QSqlQueryModel::lastError() to see what went wrong.

    Also, please put your code in code tags.
    Last edited by franz; 23rd November 2010 at 19:40.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Nov 2010
    Posts
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QString function by value

    Thanks for the reply; but I check the value by:

    Qt Code:
    1. qDebug() << "in Dialog.cpp artistv: " + artn;
    To copy to clipboard, switch view to plain text mode 

    and I get the correct name. BTW, I am retrieving value from mysql and Qt 4.6
    Last edited by Lykurg; 23rd November 2010 at 21:13. Reason: missing [code] tags

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QString function by value

    then show us how you use the function. And if you just want to query a value, you better use a single QSqlQuery and don't abuse a model for that.

  5. #5
    Join Date
    Nov 2010
    Posts
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QString function by value

    Thanks Lykurg, here is how I use the functon
    QString alakyD=Dialog::forsuly();

    which alakyD is a static QString in .h file and defined in .cpp. As I said if I use Artn="ABC" it returns Artn ABC
    Thanks again for help.

  6. #6
    Join Date
    May 2010
    Posts
    61
    Thanks
    2
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QString function by value

    Sorry for my off topic reply, but how many times does Lykurg need to edit your posts so you use [code] tags?

    Wladek
    One second is long, everything longer than two seconds is definitely too long.

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QString function by value

    With the informations you provide, I see no problem. So can you make a minimal compilable example reproducing your problem. (create a sql table in memory.)

Similar Threads

  1. call function as Qstring
    By jcr in forum Qt Programming
    Replies: 1
    Last Post: 30th May 2009, 01:35
  2. QString - no member function called 'find'
    By pitterb in forum Newbie
    Replies: 1
    Last Post: 13th January 2009, 11:31
  3. Method/Function With QString Arg
    By seanmu13 in forum Qt Programming
    Replies: 2
    Last Post: 7th July 2007, 09:43
  4. QString static callback function from CURL
    By tpf80 in forum Qt Programming
    Replies: 12
    Last Post: 16th May 2007, 20:47
  5. Using QString in C function ...
    By Godlike in forum Newbie
    Replies: 10
    Last Post: 8th April 2006, 17:01

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.