Results 1 to 8 of 8

Thread: Passing QsqlRecords in a function

  1. #1

    Default Passing QsqlRecords in a function

    Hi all,

    I am quite new to QT programming. The problem is I want to transfer sql records which I get from firing select query in my database file to another class. I'm facing problems in doing so. Can anyone please help!!!!


    thanks
    Ambarish.

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Passing QsqlRecords in a function

    How you are trying? QSqlRecord or something else.

  3. #3

    Smile Re: Passing QsqlRecords in a function

    Hi yogesh,
    Thanks for the quick reply.

    Here is how am I using QSqlRecord in my function.

    QSqlQuery q;
    QSqlRecord record;
    q.prepare(QLatin1String("select * from calendarentry where date = ?"));
    q.addBindValue(date);
    if(!q.exec())
    {
    qDebug()<<"Error while executing select Query";
    qDebug()<<q.lastError();
    }
    else
    {
    qDebug() << "Select Query fired Successfully on database for date in fetch day entries" << date;
    while(q.next())
    {
    qDebug()<<"Entries in the table are"<<q.value(0).toInt();
    qDebug()<<"Entries in the table are"<<q.value(1).toString();
    qDebug()<<"Entries in the table are"<<q.value(2).toString();
    qDebug()<<"Entries in the table are"<<q.value(3).toString();
    qDebug()<<"Entries in the table are"<<q.value(4).toString();
    qDebug()<<"Entries in the table are"<<q.value(5).toString();
    qDebug()<<"Entries in the table are"<<q.value(6).toString();
    }
    record = q.record();
    return (record);

    Now how to fetch field data from this record or is there any other way......

    And ya liked your tagline " daru vich pyar"

    Thanks,
    Ambarish

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Passing QsqlRecords in a function

    Quote Originally Posted by ambarish_singh View Post
    Now how to fetch field data from this record or is there any other way......
    Very Easy , Use:
    Qt Code:
    1. QSqlField QSqlRecord::field ( const QString & name );
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by ambarish_singh View Post
    And ya liked your tagline " daru vich pyar"
    Have you ever mixed?

  5. #5

    Post Re: Passing QsqlRecords in a function

    sorry man. I'm still not able to get the field values.

    qfield = record.field("date");
    qDebug()<<"date record is"<<qfield.value().toString();
    or
    qDebug()<<"date record is"<<qfield;
    the output is "date record is QVariant(, ) "

    Have you ever mixed?
    ya sometimes

    Thanks
    Ambarish

  6. #6
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Passing QsqlRecords in a function

    Use code tags for pasting code lines.

    Can you try this and see the result.
    Qt Code:
    1. qfield = record.field("date");
    2. if(qfield.isValid()){
    3. qDebug()<<"Field is valid named : "<<qfield.name();
    4. qDebug()<<"Field value is :"<<qfield.value().toString();
    5. }
    6. else
    7. qDebug()<<"Field is invalid ";
    To copy to clipboard, switch view to plain text mode 

  7. #7

    Default Re: Passing QsqlRecords in a function

    Hi ,

    This is the output I'm getting:

    Field is valid named : "date"
    Field value is : ""


    Thanks,
    Ambarish

  8. #8

    Default Re: Passing QsqlRecords in a function

    gotcha!!!!

    thanks for your valuable help!!!!!

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  2. Regading Driver to connect Postgresql Database
    By dummystories in forum Installation and Deployment
    Replies: 38
    Last Post: 12th March 2009, 07:19
  3. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  4. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52

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.