Results 1 to 2 of 2

Thread: no match fo 'operator[]='

  1. #1
    Join Date
    Aug 2012
    Posts
    30
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default no match fo 'operator[]='

    I am trying to make my own SVGGenerator.
    here is my displaywidget.h:


    Qt Code:
    1. #ifndef DISPLAYWIDGET_H
    2. #define DISPLAYWIDGET_H
    3.  
    4. #include <QHash>
    5. #include <QWidget>
    6.  
    7. class DisplayWidget : public [qtclass]QWidget[/qtclass]
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. enum Shape { BStar = 0, RStar = 1 };
    13. enum Background { BBackground = 0, CBackground = 1, PBackground = 2 };
    14.  
    15. DisplayWidget([qtclass]QWidget[/qtclass] *parent = 0);
    16. void paint([qtclass]QPainter[/qtclass] &painter);
    17.  
    18. public slots:
    19. void setBackground(Background background);
    20. void setShape(Shape shape);
    21.  
    22. protected:
    23. void paintEvent([qtclass]QPaintEvent[/qtclass] *event);
    24.  
    25. private:
    26. Background background;
    27. Shape shape;
    28. QHash<Shape,QPainterPath> shapeMap;
    29. };
    30. #endif // DISPLAYWIDGET_H
    31.  
    32.  
    33. here is my displaywidget.cpp:
    34.  
    35.  
    36. #include <QtGui>
    37. #include "displaywidget.h"
    38.  
    39. DisplayWidget::DisplayWidget([qtclass]QWidget[/qtclass] *parent)
    40. : QWidget(parent)
    41. {
    42. [qtclass]QPainterPath[/qtclass] BStar;
    43. [qtclass]QPainterPath[/qtclass] RStar;
    44.  
    45. [qtclass]QFile[/qtclass] file(":SVGGenerator/files/*.svg");
    46. file.open(QFile::ReadOnly);
    47. [qtclass]QDataStream[/qtclass] stream(&file);
    48. stream >> RStar >> BStar;
    49. file.close();
    50.  
    51. shapeMap[RStar] = RStar; [COLOR="#FF0000"]// no match for 'operator[]' in '((DisplayWidget*)this)->DisplayWidget::shapeMap[RStar]'[/COLOR]
    52. shapeMap[BStar] = BStar;[COLOR="#FF0000"] // no match for 'operator[]' in '((DisplayWidget*)this)->DisplayWidget::shapeMap[BStar]'[/COLOR]
    53.  
    54. background = BBackground;
    55. shape = BStar; [COLOR="#FF0000"]// cannot convert 'QPainterPath' to 'DisplayWidget::Shape' in assignment[/COLOR]
    56. }
    57.  
    58. void DisplayWidget::paintEvent([qtclass]QPaintEvent[/qtclass] * /* event */)
    59. {
    60. [qtclass]QPainter[/qtclass] painter;
    61. painter.begin(this);
    62. painter.setRenderHint(QPainter::Antialiasing);
    63. paint(painter);
    64. painter.end();
    65. }
    66.  
    67. void DisplayWidget::paint([qtclass]QPainter[/qtclass] &painter)
    68. {
    69. painter.setClipRect(QRect(0, 0, 200, 200));
    70. painter.setPen(Qt::NoPen);
    71.  
    72.  
    73.  
    74. painter.setPen(Qt::black);
    75. painter.translate(100, 100);
    76. painter.drawPath(shapeMap[shape]);
    77. }
    78.  
    79. void DisplayWidget::setBackground(Background background)
    80. {
    81. this->background = background;
    82. update();
    83. }
    84.  
    85. void DisplayWidget::setShape(Shape shape)
    86. {
    87. this->shape = shape;
    88. update();
    89. }
    To copy to clipboard, switch view to plain text mode 

    when I try to run this I get the commented errors on my .cpp file. I added all of my .svg files to every file in my project but still I have these errors. Can somebody help me?
    Last edited by high_flyer; 16th August 2012 at 12:16. Reason: code tags

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: no match fo 'operator[]='

    Your local variables QPainterPath BStar & QPainterPath RStar are conflicting with your Shape enum.
    Please, next time, use CODE tags.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. Multiline match with QRegExp
    By bender86 in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2016, 15:14
  2. No Match for Call
    By Atomic_Sheep in forum Newbie
    Replies: 6
    Last Post: 3rd May 2012, 10:16
  3. no match for 'operator=' in...
    By toss in forum Newbie
    Replies: 2
    Last Post: 14th April 2010, 00:08
  4. Replies: 1
    Last Post: 21st September 2009, 07:30
  5. No match for operator>>
    By Salazaar in forum Newbie
    Replies: 18
    Last Post: 12th June 2007, 17:48

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.