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. giving value to int in other class from mainwindow.cpp
Forum Updated to NodeBB v4.3 + New Features

giving value to int in other class from mainwindow.cpp

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 393 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.
  • K Offline
    K Offline
    khalistan
    wrote on last edited by khalistan
    #1

    Hello. there.. I want to change variable value from mainwindow.cpp (mainwindow.h) to scene.h..
    So that i can do some logic in scene.cpp... by checking variable value;
    variable is int test;

    I have mainwindow.h which look like this
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    #include "scene.h"

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    QList<QString> clickedData;
    ~MainWindow();

    private slots:
    void on_pushButtonChange_clicked();

    private:
    Ui::MainWindow *ui;
    QGraphicsView *view; //just pointers
    QGraphicsItem *item;
    QGraphicsScene scene;
    QAction
    selectAction;
    };

    #endif // MAINWINDOW_H
    Now so if I click on on_pushButtonChange then it should give variable a value in other class called Scene

    so scene.h is like this
    #include <QGraphicsScene>
    #include <QGraphicsSceneMouseEvent>
    #include <QGraphicsView>

    class Scene : public QGraphicsScene //inherit
    {
    public:
    Scene(QObject* parent = 0); //construct.
    int test; //this should be changed so that I can do some logics
    protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *event;
    };

    #endif // SCENE_H

    Thanks for help.

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

      Hi,

      Where do you have an instance of Scene ?

      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

      • Login

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