[QtDesigner] passing a pointer from ui (QGraphicsView) as argument to another class constructor

  • Hello :)
    As said, all is in the title, in my class generated by QtDesigner, i have a ui pointer with let me access all my ui elements. I have a QGraphicsView element and i want to sent a pointer onto to another class when i instantiate it in my main class. But it's like something is not going on .... I don't understand where the issue is...Here is the code :
    @MainWindow::MainWindow(QWidget parent) :
    ui(new Ui::MainWindow)
    _speed = ui->doubleSpinBox->value();
    _iter = ui->spinBox_4->value();
    _buttonState = 1;
    int width = ui->graphicsView->width();
    int height = ui->graphicsView->height();
    graph = this->getGraphicsView(); // here is the problem i think
    _game = new( Logic(width,height,graph) ); // here is the line 15

    The log said : /Users/depassearthur/Documents/Programmation/ConwayGameOfLife-build-desktop-Qt_4_8_0_dans_le_PATH__Syst_me__Debug/../ConwayGameOfLife/mainwindow.cpp:15: erreur : expected type-specifier before ';' token

    Here is the other parts of the code
    my .h :
    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QGraphicsView>
    #include "logic.h"

    namespace Ui {
    class MainWindow;

    class MainWindow : public QMainWindow

    explicit MainWindow(QWidget *parent = 0);

    private slots:
    void on_actionQuit_triggered();

    void on_actionPreferences_triggered();
    void on_actionA_Propos_triggered();
    void on_actionEditer_le_mod_le_triggered();
    void on_Launch_clicked();

    Ui::MainWindow *ui;

    float _speed;
    int _iter;
    int _buttonState;
    Logic *_game;
    QGraphicsView* getGraphicsView();


    #endif // MAINWINDOW_H

    my function getGraphicsView() :
    @QGraphicsView* MainWindow::getGraphicsView()
    return ui->graphicsView;

    And the constructor of the other class ("logic")
    @Logic::Logic(int width, int height, QGraphicsView* graph) :_iter(1),
    _graph (graph)

    And its .h file

    #ifndef LOGIC_H
    #define LOGIC_H

    #include <QGraphicsView>

    class Logic
    Logic(int width, int height, QGraphicsView* graph);
    void launch(int iter, float speed);
    void setModel();
    void stop();

    int _iter;
    int _speed;
    int _width;
    int _height;
    QGraphicsView* _graph;


    #endif // LOGIC_H
    If someone know why i have this strange error, i take it :) !

  • Moderators

    welcome to devnet

    My French is almost non-existent anymore. But if I understand your logic correct, it is not the line where you expect the trouble. The compiler is right.
    Change to this:
    _game = new Logic(width,height,graph); // here is the line 15

  • Hello :)
    Thanks, what made you think i'm French ? (of course i am :p )
    Thanks for your very fast answer, it is now good, the problem came from this point :) thanks

  • Lifetime Qt Champion


    Your paths, slot names and user name are in french and (AFAIK) there are not a lot of french speaking country that are represented here ;)

  • Moderators

    The language was a lucky guess ;-)

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.