Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [QtDesigner] passing a pointer from ui (QGraphicsView) as argument to another class constructor
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LeB0ucEtMistere
    wrote on last edited by
    #1

    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) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    _speed = ui->doubleSpinBox->value();
    _iter = ui->spinBox_4->value();
    _buttonState = 1;
    int width = ui->graphicsView->width();
    int height = ui->graphicsView->height();
    QGraphicsView
    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
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    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();
    

    private:
    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),
    _speed(1.0),
    _width(width),
    _height(height),
    _graph (graph)
    {
    }
    @

    And its .h file

    @
    #ifndef LOGIC_H
    #define LOGIC_H

    #include <QGraphicsView>

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

    private:
    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 :) !
    Thanks
    LeB0ucEtMistere

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      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
      @

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • L Offline
        L Offline
        LeB0ucEtMistere
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          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 ;)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • K Offline
            K Offline
            koahnig
            wrote on last edited by
            #5

            The language was a lucky guess ;-)

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved