Results 1 to 16 of 16

Thread: Storage and View -> imageViewer

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Posts
    40
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Storage and View -> imageViewer

    Quote Originally Posted by jacek View Post
    Are talking here about binary .rcc file or a .cpp file generated by rcc? Anyway, you can ask Qt to compress the resource file --- it should reduce the size of SVG files.
    hm... i looked at the cpp, sry, the binary that comes out is much smaller.
    Quote Originally Posted by jacek View Post
    Not QVariant, but SQLite. It supports only text, so Qt will have to encode the data somehow. Try adding the same files to the database and compare the size of .rcc file and the database.
    So, is there a documentation about that? AFAIR, base64 would make the files 1.33 times larger
    Quote Originally Posted by jacek View Post
    Yes, only Qt knows how to read .rcc files. Another solution is to use some 3rd party library for storing those files or you can keep them as regular files.
    no, i mean the data in the database... but that would be no big deal to write a simple program that reads one file and outputs the original jpg.

  2. #2
    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: Storage and View -> imageViewer

    Quote Originally Posted by C167 View Post
    So, is there a documentation about that?
    I don't think so. I've just made a simple test program and it seems that Qt cheats when it comes to QPixmaps stored as QVariants. You will have to convert images to strings yourself.

  3. #3
    Join Date
    Jan 2006
    Location
    Socorro, NM, USA
    Posts
    29
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Storage and View -> imageViewer

    Perhaps I am missing something here, but why shall the application contain the images but not load them dynamically?

    At program start up I would rather browse through the image directory/directories, load them and store them into SQLite as BLOBs. BLOBs will be stored "as is" so neither a conversion is necessary nor will this result in an inflated data size.

    Pros:
    - All images will be automatically be stored in the DB after start up.
    - If the CD image changes with respect to new images, no recompilation is necessary.
    - A default DB could be created and put on the CD, containing already stored images which are common to all future versions.

    Cons:
    - Depending on the amount of images to be stored on start up, the time until the application is "ready" could increase significantly.
    There are 10 people in the world. Those who understand binary and those who don't.

  4. #4
    Join Date
    Jan 2008
    Posts
    40
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Storage and View -> imageViewer

    [QUOTE=Thomas;59052]Perhaps I am missing something here, but why shall the application contain the images but not load them dynamically?[QUOTE]Oh, maybe i was a bit unclear: the program+database gets copied to the cd, and the program should show the images, either from db directly or with the help of the db, from files. the discussion about containing them was about rcc's, which i use to store the button icons etc.
    Quote Originally Posted by Thomas View Post
    At program start up I would rather browse through the image directory/directories, load them and store them into SQLite as BLOBs. BLOBs will be stored "as is" so neither a conversion is necessary nor will this result in an inflated data size.
    Pros:
    - All images will be automatically be stored in the DB after start up.
    - If the CD image changes with respect to new images, no recompilation is necessary.
    - A default DB could be created and put on the CD, containing already stored images which are common to all future versions.

    Cons:
    - Depending on the amount of images to be stored on start up, the time until the application is "ready" could increase significantly.
    yea, I was unclear
    we create a CD, that contains:
    • the cdlauncher
    • a pictureDB
    • some programms
    • pictures, that should be displayed
    so, thats similar to digikam: we store information about the pics in the db right now.
    ATM, the DB contains some tables containing author-, album- and picture-information. The application loads the db and if you select an image, it gets pulled from the contruct pics/{albumname}/{filename}
    Scanning through the images at startup is problematically, because they are on the cd, which is quite slow. it would mean that we would have to browse through nearly 500MBs of images, so the program would need up to several minutes to start. impossible!
    But writing a simple two-liner, that uses the db (which already stores everything neccessary, except the pic) to collect every image and writes it into the db, that would be a good method, as we have to run it once, put everything together in an iso and mount it in the windows-vm.
    Thanks so far, i'll write a little test-prg to test how we have to deal with images in DBs
    C167

  5. #5
    Join Date
    Jan 2008
    Posts
    40
    Qt products
    Qt4
    Platforms
    Unix/X11

    Exclamation Re: Storage and View -> imageViewer

    okay, i wrote a little testapp that stores an image (or every file you give it) into a BLOB-field. the db-file grows to the size of the given image, so it should be in it, although the chars i get if i do a select to qDebug() are only 8, all unprintable. So, here's my app:
    Qt Code:
    1. int main( int argc, char *argv[] )
    2. {
    3. QCoreApplication app( argc, argv );
    4. QSqlDatabase db = QSqlDatabase::addDatabase( "QSQLITE" );
    5. db.setDatabaseName( "/home/stefan/source/qt4/cdlauncher/pictures.db" );
    6. if ( !db.open() )
    7. {
    8. qDebug() << "Opening failed";
    9. return 1;
    10. }
    11. qDebug() << "Opening successfull, using database " << db.databaseName();
    12. qDebug() << "filling an image into the DB...";
    13. QFile file( "/home/stefan/pic/space/191853main_image_feature_929_full.jpg" );
    14. QByteArray fileData;
    15. if ( file.exists() )
    16. {
    17. if ( file.open( QIODevice::ReadOnly ) )
    18. {
    19. fileData = file.readAll();
    20. file.close();
    21. }
    22. }
    23. else
    24. {
    25. qDebug() << "File " << file.fileName() << " could not be located";
    26. }
    27. QSqlQuery query("UPDATE pictures SET data=? WHERE rowid=1;");
    28. query.addBindValue(fileData);
    29. query.exec();
    30. qDebug() << query.lastError();
    31. return 0;
    32. }
    To copy to clipboard, switch view to plain text mode 
    that works everything is hardcoded, i know, but its only a test to see how it works.
    So, now i want to retrieve the data. the normal way to display an image is
    Qt Code:
    1. imgLabel->setPixmap(QPixmap::fromImage(QImage("filename")));
    To copy to clipboard, switch view to plain text mode 
    After some testing, reading and coffee-ing, i found the following way:
    Qt Code:
    1. int main( int argc, char *argv[] )
    2. {
    3. Q_INIT_RESOURCE( application );
    4. QApplication app( argc, argv );
    5. QSqlDatabase db = QSqlDatabase::addDatabase( "QSQLITE" );
    6. db.setDatabaseName( "/home/stefan/source/qt4/cdlauncher/pictures.db" );
    7. if ( !db.open() )
    8. {
    9. qDebug() << "Opening failed";
    10. return 1;
    11. }
    12. QSqlQuery query( "SELECT data FROM pictures WHERE rowid=1;" );
    13. QSqlRecord record = query.record();
    14. query.next();
    15. qDebug() << query.lastError();
    16. QByteArray ba = query.value(0).toByteArray();
    17. QWidget *wid = new QWidget();
    18. QLabel *imgLabel = new QLabel( wid );
    19. QPixmap *pic = new QPixmap();
    20. pic->loadFromData( query.value( record.indexOf( "data" ) ).toByteArray() );
    21. imgLabel->setPixmap( *pic );
    22. wid->show();
    23. return app.exec();
    24. }
    To copy to clipboard, switch view to plain text mode 
    it successfully reads out the image and displays it...
    a SELECT-query seems not to like the QSqlQuery::exec () method. So i used a single next() for that...
    So far, everything is fantastic, thank you very much Thomas and jacek

  6. #6
    Join Date
    Jan 2006
    Location
    Socorro, NM, USA
    Posts
    29
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Storage and View -> imageViewer

    One last issue.

    Make sure you delete stuff which you created with new.
    There are 10 people in the world. Those who understand binary and those who don't.

  7. #7
    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: Storage and View -> imageViewer

    Quote Originally Posted by C167 View Post
    a SELECT-query seems not to like the QSqlQuery::exec () method.
    If you pass a string to QSqlQuery constructor, it will execute it immediately. It should be:
    Qt Code:
    1. QSqlQuery query;
    2. query.prepare("UPDATE pictures SET data=? WHERE rowid=1;");
    3. query.addBindValue(fileData);
    4. query.exec();
    To copy to clipboard, switch view to plain text mode 

    And the select should be:
    Qt Code:
    1. QSqlQuery query( "SELECT data FROM pictures WHERE rowid=1;" );
    2. query.next(); // <- positions the query on the first row
    3. QSqlRecord record = query.record();
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jan 2008
    Posts
    40
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Storage and View -> imageViewer

    Quote Originally Posted by jacek View Post
    If you pass a string to QSqlQuery constructor, it will execute it immediately. It should be:
    Qt Code:
    1. QSqlQuery query;
    2. query.prepare("UPDATE pictures SET data=? WHERE rowid=1;");
    3. query.addBindValue(fileData);
    4. query.exec();
    To copy to clipboard, switch view to plain text mode 

    And the select should be:
    Qt Code:
    1. QSqlQuery query( "SELECT data FROM pictures WHERE rowid=1;" );
    2. query.next(); // <- positions the query on the first row
    3. QSqlRecord record = query.record();
    To copy to clipboard, switch view to plain text mode 
    Okay, thank you
    Quote Originally Posted by Thomas View Post
    One last issue.
    Make sure you delete stuff which you created with new.
    I thought Qt is handling such things for all the classes that inherit QObject, at least their own stuff? Okay, thx I'll add everything to my destructors

  9. #9
    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: Storage and View -> imageViewer

    Quote Originally Posted by C167 View Post
    I thought Qt is handling such things for all the classes that inherit QObject, at least their own stuff?
    Yes, it does, but only for objects that have a parent.

  10. #10
    Join Date
    Jan 2008
    Posts
    40
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Storage and View -> imageViewer

    okay, thx

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.