Results 1 to 2 of 2

Thread: Having difficulty in storing a QImage and then recovering it ..

  1. #1
    Join Date
    Jun 2010
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default Having difficulty in storing a QImage and then recovering it ..

    Ok well I'm trying implement something similar to the 'undo' function in many image drawing programs .. The problem I'm having is this: I'm trying to make a backup copy of a QImage object in a QVector (which stores upto 10 latest QImage copies for backup purposes), and then try to retrieve these backups in another function. The issue is that the backup is not being created properly (since when I try to recover a backuped image, nothing happens). I know the problem is somewhere in backing up part and not in the recovering part, since when I backup a new temporary image with a red background, it recovers perfectly ..

    This is the backing up function code:

    Qt Code:
    1. imageBackups.append(image);
    To copy to clipboard, switch view to plain text mode 

    where 'image' is the QImage object that I'm trying to backup ..

    This is an alternate backing up (stores a red colored background image) - I used this just to see if this version of backing up works, which it does:

    Qt Code:
    1. QImage newImage(QSize(100,100), QImage::Format_RGB32);
    2. newImage.fill(qRgb(255, 0, 0));
    3. imageBackups.append(newImage);
    To copy to clipboard, switch view to plain text mode 

    And here is the recovering code:

    Qt Code:
    1. image =imageBackups.at(imageBackups.size()-1);
    2. QPainter painter(&image);
    3. painter.drawImage(QPoint(0,0),imageBackups.at(imageBackups.size()-1));
    To copy to clipboard, switch view to plain text mode 

    'image' is defined exactly like newImage above, except the size which is 800x400 in this case..

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Having difficulty in storing a QImage and then recovering it ..

    Quote Originally Posted by ahmadka View Post
    Qt Code:
    1. image =imageBackups.at(imageBackups.size()-1);
    To copy to clipboard, switch view to plain text mode 
    Technically, this is wrong when you want the implement an undo stack as you also need to delete any other image after it.

    What's wrong with your code? Simple: size() returns the amount of items in your list. And at() starts counting from 0.
    If you have 2 images in your list, size() returns 2. 2-1=1. Thus, at(2-1) returns the item at position 1, which is the second item in the list and in thus the last item ;-)

    Did you know that Qt comes with undo and redo functionality?
    http://doc.qt.nokia.com/4.6/qundocommand.html

Similar Threads

  1. difficulty in conversion
    By mohanakrishnan in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2009, 10:31
  2. Flag storing
    By bismitapadhy in forum Qt Programming
    Replies: 1
    Last Post: 24th June 2009, 05:26
  3. QVariant - storing QIcons[]
    By moowy in forum Qt Programming
    Replies: 7
    Last Post: 25th August 2006, 00:41
  4. storing captions
    By vijay anandh in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 07:54
  5. Replies: 3
    Last Post: 15th March 2006, 11:44

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.