Results 1 to 12 of 12

Thread: Problem using Q3CanvasSprite and Q3CanvasPixmapArray

  1. #1
    Join Date
    Jan 2008
    Posts
    26
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Question Problem using Q3CanvasSprite and Q3CanvasPixmapArray

    Hello,

    I have the following problem. In this function:

    Qt Code:
    1. void MyCanvasView::addSprite()
    2. {
    3. Q3CanvasItem* i = new BouncyLogo(myCanvas);
    4. i->setZ(rand()%256);
    5. i->show();
    6. }
    To copy to clipboard, switch view to plain text mode 


    we create a new BouncyLogo item. The constructor for BouncyLogo is as follows:

    Qt Code:
    1. BouncyLogo::BouncyLogo(Q3Canvas* canvas):
    2. Q3CanvasSprite(0,canvas)
    3. {
    4.  
    5. logo_rtti = 1234;
    6. Q3CanvasPixmapArray logo(":/images/qt-trans.xpm");
    7. setSequence(&logo);
    8. setAnimated(TRUE);
    9. initPos();
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

    OK, the problem is that when I call the function addSprite() the application just crashes...

    Can you see anything wrong with this code?

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem using Q3CanvasSprite and Q3CanvasPixmapArray

    Could you show us the call stack from the debugger when that happens? The problem is probably in the setSequence() call - you pass a pointer to a local object that gets deleted when the constructor returns and when something tries to access this data, the application crashes because the pointer is invalid.

  3. #3
    Join Date
    Jan 2008
    Posts
    26
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: Problem using Q3CanvasSprite and Q3CanvasPixmapArray

    Quote Originally Posted by wysota View Post
    Could you show us the call stack from the debugger when that happens? The problem is probably in the setSequence() call - you pass a pointer to a local object that gets deleted when the constructor returns and when something tries to access this data, the application crashes because the pointer is invalid.
    Thanks... But, How can I see the stack from the debugger? I am using QDevelop...

    Anyway, if I change the code in this way, it doesn't work neither:

    Qt Code:
    1. Q3CanvasPixmapArray* logo = new Q3CanvasPixmapArray (":/images/qt-trans.xpm");
    2. setSequence(logo);
    To copy to clipboard, switch view to plain text mode 
    Last edited by degs2k4; 26th February 2008 at 00:32. Reason: updated contents

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem using Q3CanvasSprite and Q3CanvasPixmapArray

    Quote Originally Posted by degs2k4 View Post
    Thanks... But, How can I see the stack from the debugger? I am using QDevelop...
    Run your program under gdb and when it crashes, issue the "bt" command and paste the printed output. Just make sure the application is built in debug mode.

  5. #5
    Join Date
    Jan 2008
    Posts
    26
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem using Q3CanvasSprite and Q3CanvasPixmapArray

    Quote Originally Posted by wysota View Post
    Run your program under gdb and when it crashes, issue the "bt" command and paste the printed output. Just make sure the application is built in debug mode.
    I'm running everything under windows so I don't think I have such bt command...


    I'm sorry but I don't know much about Qt....

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem using Q3CanvasSprite and Q3CanvasPixmapArray

    Quote Originally Posted by degs2k4 View Post
    I'm running everything under windows so I don't think I have such bt command...
    This is a command in the debugger (gdb).

  7. #7
    Join Date
    Jan 2008
    Posts
    26
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem using Q3CanvasSprite and Q3CanvasPixmapArray

    OK, debugging the program with GDB gives me this output:

    (gdb) (gdb) (gdb) (gdb) (gdb) Starting program: C:/QDevelop/myeditor/bin/myeditor.exe



    Program received signal SIGSEGV, Segmentation fault.

    0x00823169 in QPixmap::height (this=0x0) at image/qpixmap_raster.cpp:196

    (gdb)
    Reegarding the stack, I unclude it in a png file attached. Please check it.
    Attached Images Attached Images

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem using Q3CanvasSprite and Q3CanvasPixmapArray

    The pixmap is null. Your Q3CanvasPixmapArray constructor is invalid. Take a look at the docs to see what the parameter does.

  9. #9
    Join Date
    Jan 2008
    Posts
    26
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem using Q3CanvasSprite and Q3CanvasPixmapArray

    Quote Originally Posted by wysota View Post
    The pixmap is null. Your Q3CanvasPixmapArray constructor is invalid. Take a look at the docs to see what the parameter does.
    The parameters of the constructor look good, they match the signature of the constructor:

    Qt Code:
    1. Q3CanvasPixmapArray* logo = new Q3CanvasPixmapArray (":/images/qt-trans.xpm");
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. Q3CanvasPixmapArray ( const QString & datafilenamepattern, int fc = 0 )
    To copy to clipboard, switch view to plain text mode 

    By the way, how did you know that the problem is there just looking at the stack?
    Last edited by degs2k4; 26th February 2008 at 14:04. Reason: reformatted to look better

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem using Q3CanvasSprite and Q3CanvasPixmapArray

    Quote Originally Posted by degs2k4 View Post
    The parameters of the constructor look good, they match the signature of the constructor:
    But the content doesn't make sense. If the signature didn't match, the application wouldn't compile. The fact that the program builds doesn't mean it will work.

    By the way, how did you know that the problem is there just looking at the stack?
    Take a look at the first line of the image. (this=0x0) means that you call a method on a null pointer.

  11. #11
    Join Date
    Jan 2008
    Posts
    26
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem using Q3CanvasSprite and Q3CanvasPixmapArray

    Quote Originally Posted by wysota View Post
    But the content doesn't make sense. If the signature didn't match, the application wouldn't compile. The fact that the program builds doesn't mean it will work.
    That's true. But I am only passing a string which I think makes sense. I have other resources that work, the path is OK and the xpm file is where it should to be... So I don't understand why it is not working...

    Take a look at the first line of the image. (this=0x0) means that you call a method on a null pointer.
    OK I see. Thanks!
    Last edited by degs2k4; 26th February 2008 at 14:29. Reason: reformatted to look better

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem using Q3CanvasSprite and Q3CanvasPixmapArray

    Quote Originally Posted by degs2k4 View Post
    That's true. But I am only passing a string which I think makes sense. I have other resources that work, the path is OK and the xpm file is where it should to be... So I don't understand why it is not working...
    Check if it gets loaded. You are obviously dealing with a null pixmap array here.

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.