Results 1 to 5 of 5

Thread: Qpainter in Constructor

  1. #1
    Join Date
    Jun 2009
    Location
    India
    Posts
    143
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Qpainter in Constructor

    Hi all,

    I created a class and places some public variables to use in class functions:

    QImage resultImage;

    Now i need to declare a QPainter too in the Public and use with all the functions.

    QPainter radar_painter(&resultImage); this code how do i declare in constructor and use the variable in all functions for drawing or updating.

    Please help me.

    Regards,
    Augus.

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qpainter in Constructor

    Qt Code:
    1. MyClass::MyClass(): radar_painter(&resultImage)
    2. {
    3.  
    4. }
    To copy to clipboard, switch view to plain text mode 

    make sure QImage is placed first in class declaration than qpainter...
    i would suggest u to use a pointer instead of the stack variable.

  3. #3
    Join Date
    Jun 2009
    Location
    India
    Posts
    143
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qpainter in Constructor

    Quote Originally Posted by MrDeath View Post
    Qt Code:
    1. MyClass::MyClass(): radar_painter(&resultImage)
    2. {
    3.  
    4. }
    To copy to clipboard, switch view to plain text mode 




    make sure QImage is placed first in class declaration than qpainter...
    i would suggest u to use a pointer instead of the stack variable.

    Hi,

    I did the same way as you have mentioned,

    Declared Qimage first and Qpainter after.

    Bit Confusing on waht you have asked to me do.

    QImage *resultimage;

    and how to pass this varaible to a QPainter in constructor ..

    If i am wrong please correct me ...If need i will put my code of waht i am trying to do..

    Please help me.

  4. #4
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qpainter in Constructor

    your code is working or not? what is the error now?

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

    Default Re: Qpainter in Constructor

    Why do you want to have the painter object as a member variable of the class? That's not how we usually use QPainter.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QPainter(&QPrinter) & QPainter(&QImage) communication
    By gufeatza in forum Qt Programming
    Replies: 2
    Last Post: 2nd February 2010, 07:25
  2. Replies: 5
    Last Post: 7th September 2009, 20:57
  3. class constructor
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2008, 18:25
  4. QPainter::save and QPAinter::restore()
    By quickNitin in forum Newbie
    Replies: 2
    Last Post: 17th June 2006, 22:11
  5. Replies: 3
    Last Post: 30th April 2006, 19:22

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.