I
I
IliaNeverov2020-11-03 11:40:13
Qt
IliaNeverov, 2020-11-03 11:40:13

How to fix error: no matching constructor for initialization of "QVector3D"?

How to fix no matching constructor for initialization of "QVector3D" error?
Here is my code:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMatrix4x4>
#include <QMainWindow>
#include <QGLWidget>
#include <QOpenGLWidget>
#include <QOpenGLShaderProgram>
#include "QOpenGLTexture"
#include "QOpenGLBuffer"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

struct Vertexofcube {
    Vertexofcube(){

    }
    Vertexofcube(QVector3D p, QVector2D t, QVector3D n):
    position(p), textureposition(t), normal(n)
    {

    }

    QVector3D position;
    QVector2D textureposition;
    QVector3D normal;
};
class MainWindow : public QOpenGLWidget
{
    Q_OBJECT

public slots:
     void FixedPaint();

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    int nWidth ,nHeight; // Размеры окна нашей программы
    void initializeGL(); // Метод для инициализирования opengl
    void resizeGL(int nWidth, int nHeight); // Метод вызываемый после каждого изменения размера окна
    void paintGL(); // Метод для вывода изображения на экран
    void initCube();
    void initShaders();
    float width;
protected:

  QOpenGLBuffer Buffer1, IndexBuffer1;
  QOpenGLTexture *texture1;
  QOpenGLShaderProgram shaderprogram;
  QMatrix4x4 projectionmatrix;

private:
    Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMatrix4x4>

void MainWindow::FixedPaint()
{

}

MainWindow::MainWindow(QWidget *parent)
    : QOpenGLWidget(parent)
    ,IndexBuffer1(QOpenGLBuffer::IndexBuffer), texture1(0)
{


}

void MainWindow::initializeGL()
{
    glClearColor(0.8,0.10,0.10,1);
    glViewport( 0, 0, nWidth, nHeight );
            glLoadIdentity();
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    initShaders();
    initCube();
}

void MainWindow::resizeGL(int nWidth, int nHeight)
{
    float aspect = nWidth / (float)nHeight;
    projectionmatrix.setToIdentity();
    projectionmatrix.perspective(45, aspect, 0.1, 10);
}

void MainWindow::paintGL()
{
  glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);

}

void MainWindow::initCube() //функция для создания куба
{
    float width2 =  width / 2.0f;// 
    QVector<Vertexofcube> vertexes;
    vertexes.append(Vertexofcube(QVector3D(-width2,width2,width2, QVector2D(0,1), QVector3D(0,0,1) ) ));// эта строка подчеркивается

}

void MainWindow::initShaders()
{
  if (!shaderprogram.addShaderFromSourceFile(QOpenGLShader::Vertex,":/vertexshader1.vsh")){
      close();
  }
  if (!shaderprogram.addShaderFromSourceFile(QOpenGLShader::Fragment,":/fragmentshader1.fsh")){
      close();
  }
  if (!shaderprogram.link()){
      close();
  }
}


MainWindow::~MainWindow()
{
    delete ui;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ananiev, 2020-11-03
@IliaNeverov

QVector3D does not have a QVector3D(const QVector3D &vector) constructor, only those described in the documentation https://doc.qt.io/qt-5/qvector3d.html
Therefore, position(p) and normal(n) initializations are not valid.
Use any other QVector3D object constructor available to solve the problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question