no matching function for call to ...



  • Hi,

    ich hoffe ich trete mit meinem Beitrag keinem auf den Schlips. Ich bin absoluter Anfänger und habe eine Frage bezüglich meines nicht ganz funktionierenden Programmiertextes (Ich bin mir auch unsicher was für Infos iher benötigt, um mir zu helfen):

    Fehlermeldung:
    Fehler: no matching function for call to 'QPainter::drawRect(QPoint&, int&, int&)'
    painter.drawRect(r_pos, r_weidth, r_height);

    #include "raster.h"
    
    #include <QPoint>
    #include <QPainter>
    #include <qmath.h>
    
    Raster::Raster()
    {
    }
    Raster::Raster(
           int posX
         , int posY
         , int weidth
         , int height
         , QColor color)
    {
        r_pos =    QPoint(posX,posY);
        r_posX =   posX;
        r_posY =   posY;
        r_weidth = weidth;
        r_height = height;
        r_color =  color;
    }
    //-------------- Draw  --------------- //
    
    void Raster::draw(QPainter & painter)
    {
        r_height = 25;
        r_weidth = 25;
    
        painter.setBrush(Qt::white);
        painter.setPen(Qt::black);
        painter.drawRect(r_pos, r_weidth, r_height);
    }
    //-------------- POSITION
    void Raster::setPosition(int x, int y)
    {
        r_pos = QPoint(x, y);
    }
    


  • Obrob schrieb:

    Ich bin absoluter Anfänger und habe eine Frage bezüglich meines nicht ganz funktionierenden Programmiertextes

    Und die Frage lautet?



  • Was die Fehlermeldung bedeutet.

    Anscheinend stimmt hier etwas nicht :

    painter.drawRect(r_pos, r_weidth, r_height);
    
    // // //
    
    void Raster::setPosition(int x, int y)
    {
        r_pos = QPoint(x, y);
    }
    
    r_raster[1].setPosition(10,10);
    

    denn irgendwie emfpängt "painter.drawRect(r_pos, r_weidth, r_height);" nicht die Werte aus r_pos.



  • Meistens liegt ein "no matching function for call to" daran, daß die Typen nicht ganz genau stimmen.
    Zeig mal die Deklarationen von r_pos, r_weidth und r_height.



  • Obrob schrieb:

    Anscheinend stimmt hier etwas nicht :

    painter.drawRect(r_pos, r_weidth, r_height);
    
    // // //
    
    void Raster::setPosition(int x, int y)
    {
        r_pos = QPoint(x, y);
    }
    
    r_raster[1].setPosition(10,10);
    

    denn irgendwie emfpängt "painter.drawRect(r_pos, r_weidth, r_height);" nicht die Werte aus r_pos.

    Dafür gibt es die Doku.

    Qt-Doku schrieb:

    void 	drawRect(const QRectF & rectangle)
    void 	drawRect(const QRect & rectangle)
    void 	drawRect(int x, int y, int width, int height)
    
    drawRect(QPoint &, int, int)
    

    existiert nicht.



  • Danke! Also muss ich QRect verwenden...
    Teilweise ist die Dokumentation noch ein wenig schwierig zu lesen für mich.
    Bitte um Entschuldigung!

    raster.h

    #ifndef RASTER_H
    #define RASTER_H
    
    #include <QPoint>
    #include <QColor>
    #include <QPainter>
    
    class Raster
    {
    public:
        Raster();
        Raster(
            int posX
          , int posY
          , int weidth
          , int height);
    
        void draw(QPainter & painter);
        void setPosition(int x, int y);
    
    private:
    
        QPoint  r_pos;
        int     r_weidth;
        int     r_height;
    
    };
    
    #endif // RASTER_H
    

    raster.cpp

    #include "raster.h"
    
    #include <QPoint>
    #include <QPainter>
    #include <qmath.h>
    
    Raster::Raster()
    {
    }
    Raster::Raster(
           int posX
         , int posY
         , int weidth
         , int height)
    {
        r_pos =    QPoint(posX,posY);
        r_weidth = weidth;
        r_height = height;
    }
    //-------------- Draw  --------------- //
    
    void Raster::draw(QPainter & painter)
    {
        r_height = 25;
        r_weidth = 25;
    
        painter.setBrush(Qt::white);
        painter.setPen(Qt::black);
        painter.drawRect(r_pos, r_weidth, r_height);
    
    }
    
    //-------------- POSITION X
    void Raster::setPosition(int x, int y)
    {
        r_pos = QPoint(x,y);
    }
    

    widget.h

    #ifndef WIDGET_H
    #define WIDGET_H
    
    #include <QWidget>
    #include <raster.h>
    #include <QPoint>
    
    namespace Ui {
    class Widget;
    }
    
    class Widget : public QWidget
    {
        Q_OBJECT
    
    public:
    
        explicit Widget(QWidget *parent = 0);
        ~Widget();
    
        void raster();
        void paintEvent(QPaintEvent *);
    
    private:
    
        Ui::Widget *ui;
    
          int r_numRaster;
          Raster * r_raster;
    
    };
    
    #endif // WIDGET_H
    

    widget.cpp

    #include "widget.h"
    #include "ui_widget.h"
    
    #include <iostream>
    #include <QPainter>
    #include <QDebug>
    #include <QPoint>
    
    Widget::Widget(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::Widget)
    {
        ui->setupUi(this);
    
        r_numRaster = 25;
        r_raster = new Raster[r_numRaster];
    }
    
    Widget::~Widget()
    {
        delete ui;
    }
    
    void Widget::raster()
    {
    
        r_raster[1].setPosition(10,10);
        repaint();
    }
    
    // ---------------------------------------- //
    // ------------paintEvent------------------ //
    // ---------------------------------------- //
    
    void Widget::paintEvent(QPaintEvent *)
    {
        QPainter painter(this);
    
        r_raster[1].draw(painter);
    }
    

Log in to reply