1

I have started a Qt Project with Qt Creator and I want to use some mathematical functions. I have included math.h. But when I want to use a function, I got an error that the function is not declared in this scope. I also tried mathc, but then I got over 20 errors in cmath. I tried a fresh Ubuntu 12 installation and newest versin of Qt Creator and also Windows 7. Both sytems produce the same error. What I am doing wrong?

#include <QtGui/QApplication>
#include "mainwindow.h"
#include <QDesktopWidget>
#include <QStyle>
#include <math.h>
#include <iostream>

using namespace std;


int main(int argc, char *argv[])
{
   QApplication a(argc, argv);
   MainWindow w;

   w.setGeometry(
    QStyle::alignedRect(
        Qt::LeftToRight,
        Qt::AlignCenter,
        w.size(),
        qApp->desktop()->availableGeometry()
    ));
   w.show();
   int i= pow(2,2);
   return a.exec();
}
user1420447
  • 35
  • 1
  • 4
  • Post an example error message. Also, can QtCreator's code analysis read the functions correctly (as in, do you have squiggly red or yellow lines under the code)? – cmannett85 Aug 11 '12 at 19:24
  • the error message: ....Qt_4_8_1_in_Pfad__System__Release/../Simulator/main.cpp:26: Fehler:'pow' was not declared in this scope – user1420447 Aug 11 '12 at 19:30
  • 1
    Your code works fine for me (minus the `MainWindow` stuff obviously), so it's safe to say that this isn't a Qt problem - it's your system. If you ctrl right click on `math.h` in QtCreator, does the file open? – cmannett85 Aug 11 '12 at 19:59
  • I solved it! There was a class in my project folder called "math" , that i created a few month ago. So Qt included the wrong file of course, now it works .. – user1420447 Aug 11 '12 at 20:36
  • at least the tip with the ctrl click showed me the way to the wrong header file, Thx for that – user1420447 Aug 11 '12 at 20:37
  • Note that in a C++ project, you shouldn't include `math.h` but `cmath`. – leemes Aug 11 '12 at 23:55

1 Answers1

0

this question might be dead, but anyhow:

you might include qmath.h

#include <qmath.h>

and use the functions of this library

qPow(2, 2); //instead of pow(2, 2)

see also <QtCore/qmath.h> - Math Functions

Michael1248
  • 150
  • 1
  • 12