Results 1 to 5 of 5

Thread: Qt3-QPainter rotate exception

  1. #1
    Join Date
    Sep 2007
    Location
    Sant'Elpidio a Mare, Italy
    Posts
    194
    Thanks
    54
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Exclamation Qt3-QPainter rotate exception

    Hi everyone,

    I know this is a nooby problem, and however I'm a Qt noob...
    My application has a window that loads an image and stores it in a QPixmapLabel.
    Then there is a button that pressed should rotate the loaded image of 27 degrees.
    The problem is that the first time it works perfectly, the second push (doing nothing else
    in the meanwhile) shows an exception, and crushes the program.
    Here I report the routine that fails:

    Qt Code:
    1. QPainter paint;
    2. QPixmap *pix=pxldest->pixmap();
    3.  
    4. if(paint.begin(&pic))
    5. {
    6. paint.rotate(27);
    7. paint.drawPixmap(0,0,*pix);
    8. paint.end();
    9. pxldest->setPicture(pic);
    10. QMessageBox::information(this,"Rotated","Image rotated");
    11. }
    To copy to clipboard, switch view to plain text mode 

    "pxldest" is the QPixmapLabel's name. Note that the exception is thrown by the line 8 during the second rotation.

    I would appreciate any sort of tip or warn about this code
    and thank you in advance to all will help!
    --
    raccoon29

    "La mia vita finirà quando non vedrò più la gente ridere...non necessariamente alle mie battute "

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPainter rotate exception

    Because the second time the label's pixmap is null since you set a QPicture instead.
    You shouldn't use setPicture, but setPixmap and instead of a QPicture use a QPixmap.

    So:
    Qt Code:
    1. QPainter paint;
    2. QPixmap *pix=pxldest->pixmap();
    3.  
    4. if(pix)
    5. {
    6. QPixmap rotated(pix->size().width(), pix->size().height());
    7. paint.rotate(27);
    8. paint.drawPixmap(0,0,*pix);
    9. paint.end();
    10. pxldest->setPixmap(rotated);
    11. QMessageBox::information(this,"Rotated","Image rotated");
    12. }
    To copy to clipboard, switch view to plain text mode 

    Regards

  3. The following user says thank you to marcel for this useful post:

    Raccoon29 (4th September 2007)

  4. #3
    Join Date
    Sep 2007
    Location
    Sant'Elpidio a Mare, Italy
    Posts
    194
    Thanks
    54
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Qt3-QPainter rotate exception

    ...ohhhh but sure!!!
    Well, I'm right a noob...
    Thank you very very much marcel !
    --
    raccoon29

    "La mia vita finirà quando non vedrò più la gente ridere...non necessariamente alle mie battute "

  5. #4
    Join Date
    Sep 2007
    Location
    Sant'Elpidio a Mare, Italy
    Posts
    194
    Thanks
    54
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Qt3-QPainter rotate exception

    Thank you marcel, but just a little modification to make it work for who watch this thread:
    Qt Code:
    1. QPainter paint;
    2. QPixmap *pix=pxldest->pixmap();
    3. if(pix)
    4. {
    5. QPixmap rotated(pix->size().width(), pix->size().height());
    6. paint.begin(&rotated);
    7. paint.rotate(27);
    8. paint.drawPixmap(0,0,*pix);
    9. paint.end();
    10. pxldest->setPixmap(rotated);
    11. QMessageBox::information(this,"Rotated","Image rotated");
    12. }
    To copy to clipboard, switch view to plain text mode 
    you just forgot the "begin" to make it be handled, did you?

    Greetings
    --
    raccoon29

    "La mia vita finirà quando non vedrò più la gente ridere...non necessariamente alle mie battute "

  6. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt3-QPainter rotate exception

    Yes, I removed from the condition and forgot to add it back.
    Well, that's what happens when you write code inline, without testing it .

    Regards

Similar Threads

  1. Replies: 7
    Last Post: 20th March 2006, 20:03
  2. QPainter rotate function
    By ir210 in forum Newbie
    Replies: 3
    Last Post: 17th January 2006, 04:31
  3. Exceptions and qApp->processEvents()
    By mcostalba in forum Qt Programming
    Replies: 3
    Last Post: 8th January 2006, 17:06

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.