MathGL 2.0: troubles with QMathGL

Help
SImon
2012-03-30
2012-10-16
  • SImon

    SImon - 2012-03-30

    Hello,

    I was really curious about MathGL 2.0 (especially the export tools!), so I
    downloaded, compiled and installed it. The implementation for using QMathGL in
    combination with mglDraw doesn't seem to have changed. So I gave it a try.

    Sub-classing mglDraw (and its int Draw(mglGraph gr) function) and setting it
    with setDraw() on the QMathGL instance is no problem. It is when I'm trying to
    do a simple gr->Box() or gr->Grid() in the int Draw(mglGraph
    gr) method that
    the application unexpectedly closes.

    The project is created using QtCreator starting a new Qt Widget Project -> Qt
    Gui Application, and looks like this:

    main.cpp:

    #include <QtGui/QApplication>
    #include "mainwindow.h"
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
    
        return a.exec();
    }
    

    testdraw.h:

    #ifndef TESTDRAW_H
    #define TESTDRAW_H
    
    #include <mgl/mgl_qt.h>
    
    class TestDraw : public mglDraw
    {
    public:
        TestDraw();
        int Draw(mglGraph *gr);
    };
    
    #endif // TESTDRAW_H
    

    testdraw.cpp

    #include "testdraw.h"
    
    TestDraw::TestDraw()
    {
    }
    
    int TestDraw::Draw(mglGraph *gr)
    {
        // THIS LINE MAKES THE APPLICATION CLOSE
        // COMMENTING IT MAKES THE APPLICATION WORK
        gr->Box();
    
        return 0;
    }
    

    mainwindow.h:

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    
    namespace Ui {
        class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
    private:
        Ui::MainWindow *ui;
    };
    
    #endif // MAINWINDOW_H
    

    Finally the use of QMathGL and TestDraw in mainwindow.cpp:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    #include "testdraw.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        QMathGL *graph = new QMathGL(this);
        graph->setSize(800,600);
    
        TestDraw *draw = new TestDraw;
        graph->setDraw(draw);
    
        graph->update();
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

    Thanks for any advice!

    Best regards,
    Simon

     
  • SImon

    SImon - 2012-03-30

    By the way: just confirmed that it does work with MathG v1.11.2. Not that that
    help a lot ;)

     
  • SImon

    SImon - 2012-04-04

    Has anyone tried this or can anyone reproduce this?

     
  • Alexey Balakin

    Alexey Balakin - 2012-04-05

    Can you check this for latest SVN? Because I'm thinking that I fixed it in
    revision 385.

     
  • SImon

    SImon - 2012-04-06

    I now get this error code at compile time:

    In file included from /usr/include/mgl/mgl_zb.h:26:0,
                     from /usr/include/mgl/mgl_qt.h:29,
                     from testdraw.h:4,
                     from mainwindow.cpp:4:
    /usr/include/mgl/mgl_ab.h:124:56: error: ‘mglDraw’ has not been declared
    In file included from testdraw.h:4:0,
                     from mainwindow.cpp:4:
    /usr/include/mgl/mgl_qt.h:103:15: error: ‘mglDraw’ has not been declared
    In file included from mainwindow.cpp:4:0:
    testdraw.h:7:1: error: expected class-name before { token
    mainwindow.cpp: In constructor MainWindow::MainWindow(QWidget*):
    mainwindow.cpp:16:24: error: no matching function for call to QMathGL::setDraw(TestDraw*&)
    mainwindow.cpp:16:24: note: candidates are:
    /usr/include/mgl/mgl_qt.h:102:7: note: void QMathGL::setDraw(int (*)(mglGraph*, void*), void*)
    /usr/include/mgl/mgl_qt.h:102:7: note:   no known conversion for argument 1 from ‘TestDraw*’ to ‘int (*)(mglGraph*, void*)’
    /usr/include/mgl/mgl_qt.h:103:7: note: void QMathGL::setDraw(int*)
    /usr/include/mgl/mgl_qt.h:103:7: note:   no known conversion for argument 1 from ‘TestDraw*’ to ‘int*’
    make: *** [mainwindow.o] Error 1
    
     
  • SImon

    SImon - 2012-04-06

    (Rev. is 401)

     
  • Alexey Balakin

    Alexey Balakin - 2012-04-07

    It seems what you are still using v.1.*

    Try update from SVN, compile library (cmake build system is the only one which
    is well tested now), install it and run "sudo ldconfig". After it add to yours
    *.pro file following line

    LIBS += -lmgl-wnd
    

    Another point is that you are still using header <mgl mgl_qt.h=""> which is for
    v.1.. In v.2. it should be <mgl qt.h="">.

    At least, this sample work on my laptop after such changes.

     
  • SImon

    SImon - 2012-04-07

    This is what happens when I do sudo make install (it doesn't install
    mgl/qt.h !):

    Install the project...
    /usr/bin/cmake -P cmake_install.cmake
    -- Install configuration: ""
    -- Installing: /usr/local/share/mathgl/fonts
    -- Up-to-date: /usr/local/share/mathgl/fonts/STIX_b.vfm
    -- Up-to-date: /usr/local/share/mathgl/fonts/STIX.vfm
    -- Up-to-date: /usr/local/share/mathgl/fonts/STIX_i.vfm
    -- Up-to-date: /usr/local/share/mathgl/fonts/STIX_bi.vfm
    -- Installing: /usr/local/lib/libmgl.so.6.0.0
    -- Up-to-date: /usr/local/lib/libmgl.so
    -- Installing: /usr/local/lib/libmgl.a
    -- Installing: /usr/local/lib/libmgl-wnd.so.6.0.0
    -- Up-to-date: /usr/local/lib/libmgl-wnd.so
    -- Removed runtime path from "/usr/local/lib/libmgl-wnd.so.6.0.0"
    -- Installing: /usr/local/lib/libmgl-wnd.a
    -- Installing: /usr/local/bin/mglconv
    -- Removed runtime path from "/usr/local/bin/mglconv"
    -- Installing: /usr/local/include/mgl
    -- Up-to-date: /usr/local/include/mgl/parser.h
    -- Up-to-date: /usr/local/include/mgl/config.h.in
    -- Up-to-date: /usr/local/include/mgl/prim.h
    -- Up-to-date: /usr/local/include/mgl/window.h
    -- Up-to-date: /usr/local/include/mgl/vect.h
    -- Up-to-date: /usr/local/include/mgl/volume.h
    -- Up-to-date: /usr/local/include/mgl/font.h
    -- Up-to-date: /usr/local/include/mgl/data.h
    -- Up-to-date: /usr/local/include/mgl/evalc.h
    -- Up-to-date: /usr/local/include/mgl/addon.h
    -- Up-to-date: /usr/local/include/mgl/mgl_cf.h
    -- Up-to-date: /usr/local/include/mgl/type.h
    -- Up-to-date: /usr/local/include/mgl/surf.h
    -- Up-to-date: /usr/local/include/mgl/base.h
    -- Up-to-date: /usr/local/include/mgl/plot.h
    -- Up-to-date: /usr/local/include/mgl/opengl.h
    -- Up-to-date: /usr/local/include/mgl/mgl.h
    -- Up-to-date: /usr/local/include/mgl/define.h
    -- Up-to-date: /usr/local/include/mgl/canvas_wnd.h
    -- Up-to-date: /usr/local/include/mgl/base_cf.h
    -- Up-to-date: /usr/local/include/mgl/canvas_cf.h
    -- Up-to-date: /usr/local/include/mgl/other.h
    -- Up-to-date: /usr/local/include/mgl/eval.h
    -- Up-to-date: /usr/local/include/mgl/cont.h
    -- Up-to-date: /usr/local/include/mgl/fit.h
    -- Up-to-date: /usr/local/include/mgl/data_cf.h
    -- Up-to-date: /usr/local/include/mgl/canvas.h
    -- Up-to-date: /usr/local/include/mgl/config.h
    -- Installing: /usr/local/bin/mgl_example
    -- Removed runtime path from "/usr/local/bin/mgl_example"
    
     
  • Alexey Balakin

    Alexey Balakin - 2012-04-07

    Do you enable Qt in cmake build options?

     
  • SImon

    SImon - 2012-04-07

    Oops! No I didn't..

    Wow, and screwed up with my includes too!! (/usr/incude/mgl was still
    there...)

    Thanks Alexey! It's working now and it would probably have been working in the
    first place, too.

    Sorry for taking up your time, I really appreciate your help!!

     
  • SImon

    SImon - 2012-04-07

    It works great, but for now, the gr->Zoom() doesn't seem to work

        gr->SetRanges(mglPoint(0, 0, 0), mglPoint(4,4,4));
        gr->FPlot("x^2", "k|2");
        gr->Zoom(0.4,0.4,0.6,0.6);
        gr->Box();
    

    Commention or uncommenting the gr->Zoom(0.4,0.4,0.6,0.6); doesn't have
    effect.

    What could be wrong?

     
  • Alexey Balakin

    Alexey Balakin - 2012-04-07

    Zoom() and View() functions are used by QMathGL and Fl_MathGL for providing
    scaling and rotation of the plot by mouse. So, they just override yours call.
    I'll add QMathGL::Zoom() function for making manual zoom of the picture.

     
  • SImon

    SImon - 2012-04-09

    Nice! :)

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks