Results 1 to 20 of 25

Thread: Getting an image from mysql database (as BLOB field) through subclassed QSqlQueryMode

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Getting an image from mysql database (as BLOB field) through subclassed QSqlQuery

    Couple of things:

    - in order to be able to use this class as a QQuickImageProvider, it needs to have a "is-a" relation ship, i.e. publically inherit from QQuickImageProvider
    - in data() it doesn't make sense to use the role as given to query the base class, after all these roles will most often be your custom roles and have no meaning for the base class
    - you are missing the roleNames() override that returns the mapping of role names (used in QML) to role numbers (using in the C++ API).

    Cheers,
    _

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

    MarkoSan (20th August 2015)

  3. #2
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Angry Re: Getting an image from mysql database (as BLOB field) through subclassed QSqlQuery

    Quote Originally Posted by anda_skoa View Post
    Couple of things:

    - in order to be able to use this class as a QQuickImageProvider, it needs to have a "is-a" relation ship, i.e. publically inherit from QQuickImageProvider
    - in data() it doesn't make sense to use the role as given to query the base class, after all these roles will most often be your custom roles and have no meaning for the base class
    - you are missing the roleNames() override that returns the mapping of role names (used in QML) to role numbers (using in the C++ API).

    Cheers,
    _
    Well, class is publicly inherited from QQuickImageProvider:
    Qt Code:
    1. class UePeopleModel : public QSqlQueryModel, QQuickImageProvider
    To copy to clipboard, switch view to plain text mode 
    I've upgraded function data(), is now ok:
    Qt Code:
    1. QVariant UePeopleModel::data(const QModelIndex &index,
    2. int role) const
    3. {
    4. QVariant value=QSqlQueryModel::data(index,
    5. role);
    6. if(value.isValid())
    7. {
    8. switch(role)
    9. {
    10. case ueRoleName:
    11. {
    12. return value.toString();
    13. } // case
    14.  
    15. case ueRoleImage:
    16. {
    17. return QString::number(index.row());
    18. } // case
    19.  
    20. default:
    21. value=QVariant();
    22. } // switch
    23. } // if
    24.  
    25. return value;
    26. } // data
    To copy to clipboard, switch view to plain text mode 
    But what do I have to put inside method UePeopleModel::image?

    Sincerely yours,
    Marko
    Qt 5.3 Opensource & Creator 3.1.2

  4. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Getting an image from mysql database (as BLOB field) through subclassed QSqlQuery

    Quote Originally Posted by MarkoSan View Post
    Well, class is publicly inherited from QQuickImageProvider:
    Qt Code:
    1. class UePeopleModel : public QSqlQueryModel, QQuickImageProvider
    To copy to clipboard, switch view to plain text mode 
    Nope. Unless your code looks different in reality, this is a private inheritance

    Quote Originally Posted by MarkoSan View Post
    I've upgraded function data(), is now ok:
    Nope, see my last comment.

    Quote Originally Posted by MarkoSan View Post
    But what do I have to put inside method UePeopleModel::image?
    You get the BLOB from the base class for the given row and then load it into a QImage.
    If the BLOB is data in a format known to Qt, then you can probably use QImage::loadFromData().

    Cheers,
    _

Similar Threads

  1. Replies: 4
    Last Post: 16th June 2011, 14:49
  2. Read BLOB from MySQL database
    By zero-n in forum Newbie
    Replies: 3
    Last Post: 22nd May 2011, 19:59
  3. How to update BLOB field in a SQLite database ?
    By aircraftstories in forum Qt Programming
    Replies: 6
    Last Post: 8th April 2011, 20:45
  4. Replies: 2
    Last Post: 17th February 2010, 14:32
  5. Replies: 1
    Last Post: 14th September 2009, 08:48

Tags for this Thread

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.