Active Topics

 


Reply
Thread Tools
Posts: 341 | Thanked: 57 times | Joined on Nov 2009
#1
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:

Code:
imageBackups.append(image);
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:

Code:
QImage newImage(QSize(100,100), QImage::Format_RGB32);
newImage.fill(qRgb(255, 0, 0));
imageBackups.append(newImage);
And here is the recovering code:

Code:
image =imageBackups.at(imageBackups.size()-1);
QPainter painter(&image);
painter.drawImage(QPoint(0,0),imageBackups.at(imageBackups.size()-1));
'image' is defined exactly like newImage above, except the size which is 800x400 in this case..
 
Posts: 190 | Thanked: 129 times | Joined on Mar 2010 @ Bavaria, Germany
#2
Code:
image =imageBackups.at(imageBackups.size()-1);
QPainter painter(&image); <--- HUH?
painter.drawImage(QPoint(0,0),imageBackups.at(imageBackups.size()-1));
What the ...? You take an image from the cache and paint it on itself? Why don't you just use QUndoStack and set the limit to 10?
 
Reply


 
Forum Jump


All times are GMT. The time now is 16:31.