Unsolved Blocked with QGraphicScene
-
You create the QGraphicsView on the stack. It will be destroyed when leaving the function.
It's unclear to me where you declare the variable "scene" -
so i have to put the QGraphicsView in :
MainWindow::~MainWindow() ?
i read the i have to declare in general my scene
-
Easiest way is to declare both Scene and View as class member variables (QGraphicsScene* and QGraphicsView*), make a "new" on them in constructor, provide the main window as parent. Then you need not worry about desctruction.
-
So in my .h ?
i do like :
QGraphicsScene scene = new QGraphicsScene (this);
QGraphicsViewview = new QGraphicsView (this);?
EDIT : And my program will work ?
normally it should display picture ( 20 * 20 ) on the scene
-
sorry to up this,
if someone could help me :/ i have to finish it for the 14/01 and i know it need few times to finish it, thanks for comprehension
-
Hi,
If you are in such a hurry, you should consider hiring someone to help you finish your project.
This forum is a community driven, you can't ask the members to take your deadlines into consideration while they are helping you on their own time.
That said, rather than absolutely trying to add everything at once to your class. Take the examples from Qt's documentation and learn how to add a pixmap properly to a scene with a view on it. Then you can add your image analysis logic.
-
I just asked for some help, i DIDNT said "help me u have no choise"
And i learn from qt doc but as you can see i tried something and i have declaration problem -
@Payx @Asperamanca already said what you should do: declare your scene and view as member variables and new them in your constructor. But not like this!
QGraphicsScene scene = new QGraphicsScene (this); QGraphicsViewview = new QGraphicsView (this);
instead do:
scene = new QGraphicsScene (this); view = new QGraphicsView (this);
-
i declared
QGraphicsScene scene;
QGraphicsView view;
in my .h
and add this :void MainWindow::on_push2_clicked() { scene = new QGraphicsScene (this); view = new QGraphicsView (this);
but i got all of this http://hpics.li/8905f8b
-
@Payx
you have to declarescene
andview
aspointer
.
and forRemplacement
, you have two choice- pass the
scene
to it - declare
Remplacement
asMainWindow
's method
- pass the
-
QGraphicsScene scene; << Here you have an object QGraphicsView view; << Same
void MainWindow::on_push2_clicked() { scene = new QGraphicsScene (this); << trying to replace the object with a pointer to a newly create object. view = new QGraphicsView (this); << same
The error you are seeing here is because QObject based classes can't be copied or assigned.
-
ok so i did this :
QGraphicsScene *scene; QGraphicsView *view;
but it tell me that scene isnt declared in my remplacement's function which is in MainWindow pus2
-
@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