PDA

View Full Version : Qt Creator - error: call of overloaded 'QMatrix4x4(const qreal*&)' is ambiguous



hasanbaghal
15th December 2017, 08:49
I have a project in Qt Creator in Windows,When compiled I got this Error, I Googled a few, But I couldn't find the solution :

\application\src\helpers.cpp:99: error: call of overloaded 'QMatrix4x4(const qreal*&)' is ambiguous
QMatrix4x4 matrix(a);
^

the line that has error:

QMatrix4x4 matrix(a);
so what should I do?

helpers.cpp corresponded to the error:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "helpers.h"
#include <QMatrix4x4>
#include <QtGui>

Helpers :: Helpers()
{
}

Helpers :: ~Helpers()
{
}

//================================================== ==================
// Normalize
//================================================== ==================

void Helpers::normalize(qreal *a)
{
double b;

b = vlen(a);
a[0] /= b;
a[1] /= b;
a[2] /= b;
}

//================================================== ==================
// Length
//================================================== ==================

qreal Helpers::vlen(qreal *a)
{
return sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]);
}

//================================================== ==================
// Cross product
//================================================== ==================

void Helpers::crossProduct(qreal *a, qreal *b, qreal *c)
{
c[0] = a[1]*b[2] - a[2]*b[1];
c[1] = a[2]*b[0] - a[0]*b[2];
c[2] = a[0]*b[1] - a[1]*b[0];
}

//================================================== ==================
// Invert 4x4 matrix (for visualiztion only)
//================================================== ==================
//commented by John
// pre start cooment
void Helpers::invertMatrix(const qreal *a, qreal *inva)
{

QMatrix4x4 matrix(a);

bool ok(true);

QMatrix4x4 inverse(matrix.transposed().inverted(&ok));

if(!ok) fprintf(stderr, "Error: Singular 4x4 matrix\n");

for(int i = 0; i < 16; ++i)
inva[i] = double(inverse.data()[i]);
}
//*/ pre end comment

This is all errors that I see,after lots of debugging... I think the problem maybe about command syntax format or libraries definition and usage or something else...

d_stranz
15th December 2017, 15:45
There is no QMatrix4x4 constructor that takes a pointer to a QMatrix4x4 as an argument. There -is- a constructor that takes a pointer to an array of float. There is no way for C++ to automatically convert a pointer to a QMatrix4x4 to a pointer to an array of float, so that is why you get a compilation error.

If you don't understand what I am hinting at, here's another hint: Look carefully at your list of arguments to "invertMatrix()" and then look at the QMatrix4x4 docs and the list of allowed arguments to its constructors, and compare that with how you are trying to construct your temporary matrix.