Results 1 to 2 of 2

Thread: pointer reference confusion

  1. #1
    Join Date
    Apr 2007
    Posts
    117
    Thanks
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default pointer reference confusion

    Hello guys I am trying to modify the Image Viewer example of qt so that it gets an image with its constructor. This is wrong... how can I correct this:
    Qt Code:
    1. ImageViewer::ImageViewer(QImage *image){
    2. .....
    3. QPixmap pixmap = QPixmap::fromImage(*image);
    4. QPixmap pixmap2 = QPixmap::fromImage(&image);
    5. .....
    6. }
    To copy to clipboard, switch view to plain text mode 

    The new ImageViewer terminates upon imageviewer show
    Image Analysis Development Framework Using Qt (IADFUQ)

  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: pointer reference confusion

    Why do you need to pass a QImage pointer pointer?

    QPixmap::fromImage takes a const Image&.
    So the statement:
    Qt Code:
    1. QPixmap pixmap = QPixmap::fromImage(*image);
    To copy to clipboard, switch view to plain text mode 
    is correct as long as image is a valid pointer.

    It probably crashes because the image pointer is null or not valid.
    I say the best way is to pass a const QImage& also, since QImage is implicitly shared.

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

    sincnarf (14th October 2007)

Similar Threads

  1. Replies: 5
    Last Post: 7th November 2007, 14:46
  2. MS Sql native driver??
    By LordQt in forum Qt Programming
    Replies: 4
    Last Post: 9th October 2007, 13:41
  3. error undefined reference ...............
    By amit_pansuria in forum Qt Programming
    Replies: 2
    Last Post: 8th June 2007, 14:28
  4. how to correctly compile threads support?
    By srhlefty in forum Installation and Deployment
    Replies: 9
    Last Post: 25th June 2006, 19:15
  5. Strange error while using Q3Canvas
    By Kapil in forum Newbie
    Replies: 13
    Last Post: 15th June 2006, 19:36

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.