Results 1 to 5 of 5

Thread: Inserting blob into mysql using QT?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Inserting blob into mysql using QT?

    i create a class to manage BLOB fields. i tested in SQLITE and FIREBIRD. i think must work in MYSQL

    Qt Code:
    1. class SqlFieldBlob : public QObject
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit SqlFieldBlob(QObject *parent = 0);
    6.  
    7. QByteArray data() { return p_byteArray; }
    8. bool saveData(const QString &filename);
    9.  
    10. public slots:
    11. void setData(const QByteArray &byteArray) { p_byteArray = byteArray;}
    12. void setFileName(const QString &filename);
    13. void setPixmap(const QPixmap &pixmap);
    14.  
    15. private:
    16. QByteArray p_byteArray;
    17. };
    To copy to clipboard, switch view to plain text mode 

    and using something like
    Qt Code:
    1. SqlFieldBlob blob;
    2. blob.setFileName(fileName);
    3.  
    4. QSqlQuery query2;
    5. query2.prepare("INSERT INTO files (file_name, file_data) "
    6. "VALUES (:id, :id2)");
    7. query2.bindValue("id", fileName);
    8. query2.bindValue("id2", blob.data());
    9. query2.exec();
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files
    Last edited by ecanela; 31st August 2010 at 04:31. Reason: updated contents

  2. The following user says thank you to ecanela for this useful post:

    guitronic (17th July 2014)

  3. #2
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Inserting blob into mysql using QT?

    code to convert a QPixmap in a QByteArray

    Qt Code:
    1. QByteArray BlobClass::convertPixmap(const QPixmap &pixmap)
    2. {
    3. QByteArray bytes;
    4. QBuffer buffer(&bytes);
    5. buffer.open(QIODevice::WriteOnly);
    6. pixmap.save(&buffer, "PNG");
    7. return buffer.data();
    8. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. problem: inserting a BLOB into sqlite3 with QT4.3
    By oscar in forum Qt Programming
    Replies: 1
    Last Post: 18th November 2007, 12:38
  2. mysql configuration with qt
    By bala in forum Installation and Deployment
    Replies: 3
    Last Post: 6th November 2007, 11:02
  3. MySQL starting problem
    By shamik in forum General Discussion
    Replies: 5
    Last Post: 25th April 2007, 07:20
  4. Qt 4.1.4 & Mysql 5 on Linux x64
    By bothapn in forum Installation and Deployment
    Replies: 7
    Last Post: 4th August 2006, 13:23
  5. Qt 4.1 OS on Windows & mysql
    By neeko in forum Installation and Deployment
    Replies: 10
    Last Post: 31st January 2006, 20:22

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
  •  
Qt is a trademark of The Qt Company.