View Full Version : Qt and muParser
RavenS
14th April 2009, 16:20
Good evening.
Someone used muParser? (http://muparser.sourceforge.net/) I am interested in how you can embed it in the Qt-application.
My attempts is not allowed. Displays a lot of errors, in particular, "undefined reference to `vtable for mu:: Parser '"
lyuts
14th April 2009, 17:31
Did you add the path to muParser's libs to DEPENDPATH variable in your .pro file?
RavenS
14th April 2009, 18:48
Yes, i solved this problem, but i can't understand what to do with the next error:
"no matching function for call to `mu::Parser::DefineFun(const char[7], <unknown type>, bool)'"
It seems that my callback function have invalid declaration, but i just copied example code and tried to compile it. I tried to use mu::value_type as type of returning value, but it still doesn't works.
lyuts
14th April 2009, 18:54
Can you show us some code?
RavenS
14th April 2009, 19:20
Here it is.
#include "someClass.h"
#include <QString>
#include <muParser.h>
double someClass::MyFunction(double a_fVal)
{
return a_fVal*a_fVal;
}
double someClass::eval()
{
using namespace mu;
try
{
double fVal = 1;
Parser p;
p.DefineVar("a", &fVal);
p.DefineFun(_T("MyFunc"), MyFunction, false);
p.SetExpr("MyFunc(a)*_pi+min(10,a)");
return p.Eval();
}
catch (Parser::exception_type &e)
{
qDebug() << "Error!";
//std::cout << e.GetMsg() << endl;
}
return 0;
}
When i'm trying to compile i get this:
"no matching function for call to `mu::Parser::DefineFun(const char[7], <unknown type>, bool)'"
This is a little example on http://muparser.sourceforge.net/mup_version.html#idExample :
#include "muParser.h"
// Function callback
double MyFunction(double a_fVal)
{
return a_fVal*a_fVal;
}
// main program
int main(int argc, char* argv[])
{
using namespace mu;
try
{
double fVal = 1;
Parser p;
p.DefineVar("a", &fVal);
p.DefineFun("MyFunc", MyFunction);
p.SetExpr("MyFunc(a)*_pi+min(10,a)");
std::cout << p.Eval() << endl;
}
catch (Parser::exception_type &e)
{
std::cout << e.GetMsg() << endl;
}
return 0;
}
As you can see, they are equal.
lyuts
14th April 2009, 19:29
Well, they are not equal. I don't know the exact signature, as well as _T function but
your code has a call passing a bool variable
p.DefineFun(_T("MyFunc"), MyFunction, false);
While example code has this call
p.DefineFun("MyFunc", MyFunction);
lyuts
14th April 2009, 19:33
Ok, sorry...
I got the correct signature
inline void DefineFun(const string_type &a_strName, TYPE a_pFun, bool a_bAllowOpt = true)
Then, i have just noticed, that the example is passing the a regular function, while you are trying to to pass a function that is a class member.
RavenS
14th April 2009, 19:33
I found this expression in additional muParser examples, and tried, but in this case it doesn't work too. :(
Not first, nor second variant.
RavenS
14th April 2009, 19:37
Wow! It works!
Thank you very much!
lyuts
14th April 2009, 19:38
By the way, take a look at this
http://www.parashift.com/c++-faq-lite/pointers-to-members.html#faq-33.2
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.