Results 1 to 10 of 10

Thread: Qt and muParser

  1. #1
    Join Date
    Feb 2009
    Location
    Russia, Siberia, Novosibirsk
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qt and muParser

    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 '"
    Sorry for my bad english.

  2. #2
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt and muParser

    Did you add the path to muParser's libs to DEPENDPATH variable in your .pro file?
    I'm a rebel in the S.D.G.

  3. #3
    Join Date
    Feb 2009
    Location
    Russia, Siberia, Novosibirsk
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt and muParser

    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.
    Sorry for my bad english.

  4. #4
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt and muParser

    Can you show us some code?
    I'm a rebel in the S.D.G.

  5. #5
    Join Date
    Feb 2009
    Location
    Russia, Siberia, Novosibirsk
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt and muParser

    Here it is.

    Qt Code:
    1. #include "someClass.h"
    2. #include <QString>
    3.  
    4. #include <muParser.h>
    5.  
    6. double someClass::MyFunction(double a_fVal)
    7. {
    8. return a_fVal*a_fVal;
    9. }
    10.  
    11. double someClass::eval()
    12. {
    13. using namespace mu;
    14. try
    15. {
    16. double fVal = 1;
    17. Parser p;
    18. p.DefineVar("a", &fVal);
    19. p.DefineFun(_T("MyFunc"), MyFunction, false);
    20. p.SetExpr("MyFunc(a)*_pi+min(10,a)");
    21. return p.Eval();
    22. }
    23. catch (Parser::exception_type &e)
    24. {
    25. qDebug() << "Error!";
    26. //std::cout << e.GetMsg() << endl;
    27. }
    28.  
    29. return 0;
    30. }
    To copy to clipboard, switch view to plain text mode 
    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_...html#idExample :
    Qt Code:
    1. #include "muParser.h"
    2.  
    3. // Function callback
    4. double MyFunction(double a_fVal)
    5. {
    6. return a_fVal*a_fVal;
    7. }
    8.  
    9. // main program
    10. int main(int argc, char* argv[])
    11. {
    12. using namespace mu;
    13.  
    14. try
    15. {
    16. double fVal = 1;
    17. Parser p;
    18. p.DefineVar("a", &fVal);
    19. p.DefineFun("MyFunc", MyFunction);
    20. p.SetExpr("MyFunc(a)*_pi+min(10,a)");
    21. std::cout << p.Eval() << endl;
    22. }
    23. catch (Parser::exception_type &e)
    24. {
    25. std::cout << e.GetMsg() << endl;
    26. }
    27. return 0;
    28. }
    To copy to clipboard, switch view to plain text mode 
    As you can see, they are equal.
    Sorry for my bad english.

  6. #6
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt and muParser

    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

    Qt Code:
    1. p.DefineFun(_T("MyFunc"), MyFunction, false);
    To copy to clipboard, switch view to plain text mode 

    While example code has this call

    Qt Code:
    1. p.DefineFun("MyFunc", MyFunction);
    To copy to clipboard, switch view to plain text mode 
    I'm a rebel in the S.D.G.

  7. #7
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt and muParser

    Ok, sorry...
    I got the correct signature

    Qt Code:
    1. inline void DefineFun(const string_type &a_strName, TYPE a_pFun, bool a_bAllowOpt = true)
    To copy to clipboard, switch view to plain text mode 

    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.
    I'm a rebel in the S.D.G.

  8. The following user says thank you to lyuts for this useful post:

    RavenS (14th April 2009)

  9. #8
    Join Date
    Feb 2009
    Location
    Russia, Siberia, Novosibirsk
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt and muParser

    I found this expression in additional muParser examples, and tried, but in this case it doesn't work too.
    Not first, nor second variant.
    Sorry for my bad english.

  10. #9
    Join Date
    Feb 2009
    Location
    Russia, Siberia, Novosibirsk
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt and muParser

    Wow! It works!
    Thank you very much!
    Sorry for my bad english.

  11. #10
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt and muParser

    I'm a rebel in the S.D.G.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.