Results 1 to 7 of 7

Thread: help with pointers and

  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 help with pointers and

    Hello!

    I am using Qt4.2.3.

    Please help me with pointers and correct this piece of code. And if possible, put some explanation on why I enounter errors such as "functional cast expression list treated as compound expression" and "no matching call' errors. Thanks in advance

    Qt Code:
    1. void MainWinow::doFunction1()
    2. {
    3. QImage *image = new QImage(QSize(100,100), QImage::Format_RGB32);
    4.  
    5. int x = 0;
    6. int y = 0;
    7. for (x= 0; x < image->width(); x++){
    8. for (y = 0; y < image->height(); y++){
    9. image->setPixel(x, y, QRgb(255,0,0));
    10. }
    11. }
    12.  
    13. item->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
    14. item->setFlag(QGraphicsItem::ItemIsMovable);
    15. scene->addPixmap(QPixmap::fromImage(&image));
    16.  
    17. //graphicsViewVis is globally declared
    18. graphicsViewVis->setScene(scene);
    19. graphicsViewVis->show();
    20.  
    21. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: help with pointers and

    Quote Originally Posted by sincnarf View Post
    Hello!

    I am using Qt4.2.3.

    Please help me with pointers and correct this piece of code. And if possible, put some explanation on why I enounter errors such as "functional cast expression list treated as compound expression" and "no matching call' errors. Thanks in advance

    Qt Code:
    1. scene->addPixmap(QPixmap::fromImage(&image));
    To copy to clipboard, switch view to plain text mode 
    Change it to
    Qt Code:
    1. scene->addPixmap(QPixmap::fromImage(*image));
    To copy to clipboard, switch view to plain text mode 
    You are trying to pass QImage** to a function which takes const QImage& as parameter.
    Last edited by Gopala Krishna; 1st July 2007 at 21:30. Reason: missing [code] tags
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

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

    sincnarf (4th October 2007)

  4. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: help with pointers and

    Side notes: there is no need to allocate image on the heap and item is never initialized.
    J-P Nurmi

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

    Default Re: help with pointers and

    Thanks for the help! I changed the lines 5 to 11 into
    Qt Code:
    1. int x = 0;
    2. int y = 0;
    3. for (x= 0; x < image.width(); x++){
    4. for (y = 0; y < image.height(); y++){
    5. image.setPixel(x, y, QRgb(255,0,0));
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

    and it produces the error

    mainwindow.cpp:139: error: functional cast expression list treated as compound expression
    mainwindow.cpp:139: warning: left-hand operand of comma has no effect
    mainwindow.cpp:139: warning: right-hand operand of comma has no effect

  6. #5
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: help with pointers and

    Change line no 3 in your first snippet to
    Qt Code:
    1. QImage image(QSize(100,100), QImage::Format_RGB32);
    To copy to clipboard, switch view to plain text mode 
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  7. The following user says thank you to Gopala Krishna for this useful post:

    sincnarf (4th October 2007)

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

    Default Re: help with pointers and an error I dont' know of

    This is my code
    Qt Code:
    1. void MainWindow::doFunction1()
    2. {
    3. QImage image(QSize(100,100), QImage::Format_RGB32);
    4.  
    5. int x = 0;
    6. int y = 0;
    7. for (x= 0; x < image.width(); x++){
    8. for (y = 0; y < image.height(); y++){
    9. image.setPixel(x, y, QRgb(255,0,0));
    10. }
    11. }
    12.  
    13. item->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
    14. item->setFlag(QGraphicsItem::ItemIsMovable);
    15. scene->addPixmap(QPixmap::fromImage(image));
    16.  
    17. graphicsViewVis->setScene(scene);
    18. graphicsViewVis->show();
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 

    on compilation, there are errors and warnings :
    error: functional cast expression list treated as compound expression
    warning: left-hand operand of comma has no effect
    warning: right-hand operand of comma has no effect

    it is noted that the line image.setPixel(x, y, QRgb(255,0,0)); is underlined in red. this is where the error is. Thanks in advance to those who can explain to me how to solve the error functional cast expression list treated as compound expression.

  9. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: help with pointers and

    It should be "qRgb(255,0,0)". Notice comments in earlier posts; variable "QGraphicsPixmapItem *item" is still used as uninitialized so a crash will follow.
    J-P Nurmi

  10. The following user says thank you to jpn for this useful post:

    sincnarf (4th October 2007)

Similar Threads

  1. pointers in c++
    By :db:sStrong in forum General Programming
    Replies: 1
    Last Post: 4th June 2007, 09:56
  2. Use/Misuse of Pointers
    By ct in forum General Programming
    Replies: 12
    Last Post: 8th May 2007, 23:43
  3. Pointer to a 2D array of pointers ??
    By aamer4yu in forum General Programming
    Replies: 2
    Last Post: 1st February 2007, 11:16
  4. Problem with pointers while using localtime() and time()
    By jamadagni in forum General Programming
    Replies: 7
    Last Post: 11th January 2006, 15:48
  5. K&R's strcpy function - problem with pointers
    By jamadagni in forum General Programming
    Replies: 7
    Last Post: 8th January 2006, 15:16

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.