Results 1 to 9 of 9

Thread: Compile error for Qpainter

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    56
    Thanked 1 Time in 1 Post

    Default Compile error for Qpainter

    I have the next errors. On the analog clock I have create a new function 'dibuja' that uses the 'thepainter' qpainter object ( in this case I use a previous image)

    error: request for member 'translate' in 'painter', which is of non-class type 'QPainter*'
    error: request for member 'scale' in 'painter', which is of non-class type 'QPainter*'
    error: request for member 'setBrush' in 'painter', which is of non-class type 'QPainter*'
    and etc..

    Here is a piece of code :

    QPainter thepainter(&image);
    dibuja( &thepainter, thetime);

    void AnalogClock::dibuja(QPainter *painter, QTime time)

    My last code worked, I had all the code that now is in 'dibuja' at the paintevent. I have only placed the Qpainter code at a new function.
    Why I have theese errors ?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: Compile error for Qpainter

    Well, in your function you probably call something like
    Qt Code:
    1. painter.translate();
    To copy to clipboard, switch view to plain text mode 
    but it must be
    Qt Code:
    1. painter->translate();
    To copy to clipboard, switch view to plain text mode 
    because in the function you have a pointer.

  3. #3
    Join Date
    Sep 2010
    Posts
    654
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    56
    Thanked 1 Time in 1 Post

    Default Re: Compile error for Qpainter

    AH ! Stupid me .
    But, Why I can not to use without pointer ? This are the errors if I use no-pointer scheme...

    ..\..\..\include/QtGui/../../src/gui/painting/qpainter.h: In member function 'virtual void AnalogClock:aintEvent(QPaintEvent*)':
    ..\..\..\include/QtGui/../../src/gui/painting/qpainter.h:503: error: 'QPainter::QPainter(const QPainter&)' is private
    ..\analogclock\analogclock.cpp:115: error: within this context
    ..\analogclock\analogclock.cpp:115: error: initializing argument 1 of 'void AnalogClock::dibuja(QPainter, QTime)'
    Last edited by tonnot; 7th October 2010 at 09:36.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: Compile error for Qpainter

    Whats the problem with using a pointer? And could you please show the real (simplified) source code alongside the error, that one could better see what exactly you do.

  5. #5
    Join Date
    Sep 2010
    Posts
    654
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    56
    Thanked 1 Time in 1 Post

    Default Re: Compile error for Qpainter

    This is the code.
    It is an ampliation of analog example, with a second indicator
    And I want to draw a hundredth indicator, but I'm trying to use a image 'record' (to avoid to draw everything at the hundredth.

    I must to pass Qpainter using pointer, if not I have the errors...



    analog.h
    Qt Code:
    1. #ifndef ANALOGCLOCK_H
    2. #define ANALOGCLOCK_H
    3.  
    4. #include <QWidget>
    5. #include <QTime>
    6.  
    7. class AnalogClock : public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. AnalogClock(QWidget *parent = 0);
    13. void dibuja(QPainter *painter, QTime time);
    14.  
    15. protected:
    16. void paintEvent(QPaintEvent *event);
    17. void resizeEvent(QResizeEvent *event);
    18. };
    19.  
    20. #endif
    To copy to clipboard, switch view to plain text mode 

    analog.cpp
    Qt Code:
    1. #include <QtGui>
    2.  
    3. #include "analogclock.h"
    4. #include <qdebug>
    5.  
    6.  
    7. int segundo=0;
    8. QImage image;
    9.  
    10.  
    11. static const QPoint hourHand[3] = {
    12. QPoint(7, 8),
    13. QPoint(-7, 8),
    14. QPoint(0, -40)
    15. };
    16. static const QPoint minuteHand[3] = {
    17. QPoint(7, 8),
    18. QPoint(-7, 8),
    19. QPoint(0, -60)
    20. };
    21. static const QPoint secondHand[3] = {
    22. QPoint(3, 12),
    23. QPoint(-3, 12),
    24. QPoint(0, -70)
    25. };
    26. static const QPoint centesima[3] = {
    27. QPoint(2, 12),
    28. QPoint(-2, 12),
    29. QPoint(0, -80)
    30. };
    31.  
    32.  
    33.  
    34.  
    35. QColor hourColor(127, 0, 127);
    36. QColor minuteColor(0, 127, 127, 191);
    37. QColor secondColor(255, 127, 127, 191);
    38. QColor centeColor(255, 127, 127, 191);
    39.  
    40. void laimagen(int x, int y)
    41. {
    42. image= QImage(x, y, QImage::Format_ARGB32_Premultiplied); //QImage::Format_RGB32
    43.  
    44. }
    45.  
    46. AnalogClock::AnalogClock(QWidget *parent) : QWidget(parent)
    47.  
    48. {
    49. QTimer *timer = new QTimer(this);
    50.  
    51. connect(timer, SIGNAL(timeout()), this, SLOT(update()));
    52.  
    53. setWindowTitle(tr("Analog Clock"));
    54. resize(200, 200);
    55. segundo=0;
    56. laimagen(200,200);
    57. timer->start(10);
    58.  
    59. }
    60.  
    61.  
    62. void AnalogClock::paintEvent(QPaintEvent *)
    63.  
    64. {
    65. QTime thetime = QTime::currentTime();
    66. if (segundo==0) segundo=thetime.second();
    67.  
    68. if (thetime.second()==segundo )
    69. {
    70. QPainter thepainter(&image); // se pinta en la imagen
    71. dibuja( &thepainter, thetime);
    72. segundo=(++segundo==60)?0:segundo++;
    73. }
    74. else
    75. {
    76. QPainter thepainter(this);
    77. thepainter.drawImage(image.rect(), image, image.rect());
    78. }
    79. }
    80.  
    81. void AnalogClock::resizeEvent(QResizeEvent *event) {
    82. int wi=event->size().width();
    83. int he=event->size().height();
    84. laimagen(wi,he);
    85. }
    86.  
    87. void AnalogClock::dibuja(QPainter *painter, QTime time) {
    88. int side = qMin(width(), height());
    89. painter->setRenderHint(QPainter::Antialiasing);
    90. painter->translate(width() / 2, height() / 2);
    91. painter->scale(side / 200.0, side / 200.0);
    92.  
    93. painter->setPen(Qt::NoPen);
    94. painter->setBrush(hourColor);
    95. painter->save();
    96. painter->rotate(30.0 * ((time.hour() + time.minute() / 60.0)));
    97. painter->drawConvexPolygon(hourHand, 3);
    98.  
    99. painter->restore();
    100. painter->setPen(hourColor);
    101. for (int i = 0; i < 12; ++i) {
    102. painter->drawLine(88, 0, 96, 0);
    103. painter->rotate(30.0);
    104. }
    105. painter->setPen(Qt::NoPen);
    106. painter->setBrush(minuteColor);
    107. painter->save();
    108. painter->rotate(6.0 * (time.minute() + time.second() / 60.0));
    109. painter->drawConvexPolygon(minuteHand, 3);
    110. painter->restore();
    111. painter->save();
    112. painter->rotate(time.second()*6.0);
    113. painter->drawConvexPolygon(secondHand, 3);
    114. painter->restore();
    115. painter->save();
    116. painter->setPen(minuteColor);
    117. for (int j = 0; j < 60; ++j) {
    118. if ((j % 5) != 0)
    119. painter->drawLine(92, 0, 96, 0);
    120. painter->rotate(6.0);
    121. }
    122. painter->restore();
    123. painter->save();
    124. painter->setPen(centeColor);
    125. for (int j = 0; j < 360; ++j) {
    126. painter->drawLine(90, 0, 92, 0);
    127. painter->rotate(1.0);
    128. }
    129. painter->restore();
    130. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Compile error for Qpainter

    QObject and Classes derived from it (eg QPainter) have their copy constructor and assignment operator private. so u can not do QPainter = QPainter.

    EDIT: QPainter is not derived from QObject, but from the error it looks like it still has its cctor private
    Last edited by nish; 7th October 2010 at 11:36.

  7. #7
    Join Date
    Sep 2010
    Posts
    654
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    56
    Thanked 1 Time in 1 Post

    Default Re: Compile error for Qpainter

    MrDearh, can you explain me more about assignment operator private ?
    And thanks for the answer

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

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

    Default Re: Compile error for Qpainter

    QPainter is not derived from QObject, but it follows the same rule of private ctor.

Similar Threads

  1. no compile error, but error on run with QMenu QAction
    By sincnarf in forum Qt Programming
    Replies: 4
    Last Post: 4th May 2011, 12:05
  2. QPainter/QImage/memory management error
    By p3l-outrepid in forum Qt Programming
    Replies: 0
    Last Post: 10th May 2010, 13:53
  3. QPainter error saving an image from a QGraphicsScene
    By cydside in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2010, 05:53
  4. Error while redrawing using QPainter Class
    By sosanjay in forum Qt Programming
    Replies: 5
    Last Post: 28th December 2009, 12:48
  5. ERROR:: QPainter: Internal error; no available GC
    By Krishnacins in forum Qt Programming
    Replies: 2
    Last Post: 8th March 2006, 07:05

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.