Unsolved Blocked with QGraphicScene
-
@Flotisable said in Blocked with QGraphicScene:
@Payx
and forRemplacement
, you have two choice- pass the
scene
to it - declare
Remplacement
asMainWindow
's method
I have said about it
- pass the
-
There's no need to replace anything, just create them in the constructor and be done with that part.
When you want to modify the content of the scene you can for example clean it completely (there are other solution but it looks like the most simple in the current situation).
-
@SGaist sorry but, i don't understand well the "create in the constructor"
-
@Payx C++ constructor?
class MainWindow : public QMainWindow { Q_OBJECT public: QPixmap pixa; explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private slots: void on_push_clicked(); void on_push2_clicked(); void on_verticalSlider_sliderMoved(int position); void on_verticalSlider_actionTriggered(int action); private: Ui::MainWindow *ui; QImage pixi; QGraphicsScene *scene; QGraphicsView *view; float k; int a; int z=1; int b; }; // In cpp file // This is the constructor MainWindow::MainWindow(QWidget *parent) { ... scene = new QGraphicsScene (this); view = new QGraphicsView (this); }
-
so it's exactly what i did, but have still the "scene isnt declared"
-
@Payx
First I see some basic structural things. You do not need to #include in both your .h and .cpp. Although Qt uses smart includes, it is a waste of time. Just forward declare the pointers variables needed in your .h file. For example:class QGraphicsView;
class QGraphicsScene;
. . .
QGraphicsScene* scene;
QGraphicsView* view;In your .cpp file go ahead and include them.
The second thing I saw and I haven't seen it addressed is your usage of the member 'scene'. Your code still indicates you are using it as an object and not a pointer. So, you can remove the use of '&' and use '->' instead of '.'
You can get some weird errors when you mix.
-
i use -> here ?
scene->addItem(item); -
@Payx
yes -
same error
-
Did you cleanup all your code ?
Did you cleanup your includes ? -
Not to sound harsh but you should probably learn the basics of c++, like what is a constructor :O