PDA

View Full Version : Problem with GUIs



trallallero
28th October 2009, 14:21
I have a class derived from QGraphicsView that creates a GUI only if created by the main.
So, this works:

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QGraphicsScene scene;
scene.setSceneRect(0, 0, 1024, 768);
scene.setBackgroundBrush(QColor::fromRgb(47, 51, 47));

gui view(&scene);
view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlw aysOff);
view.setVerticalScrollBarPolicy(Qt::ScrollBarAlway sOff);
view.setWindowFlags(Qt::FramelessWindowHint) ;
view.setCacheMode(QGraphicsView::CacheBackground);
view.setDragMode(QGraphicsView::NoDrag);
view.setFixedSize(1024, 768);
view.show();

return a.exec();
}


And this doesn't work:


int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Starter s;
return a.exec();
}


class Starter : public QObject
{
Q_OBJECT

public:
Starter();
};



Starter::Starter()
{
QGraphicsScene s;
s.setSceneRect(0, 0, 1024, 768);
s.setBackgroundBrush(QColor::fromRgb(47, 51, 47));

gui view(&s);

view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlw aysOff);
view.setVerticalScrollBarPolicy(Qt::ScrollBarAlway sOff);
view.setWindowFlags(Qt::FramelessWindowHint) ;
view.setCacheMode(QGraphicsView::CacheBackground);
view.setDragMode(QGraphicsView::NoDrag);
view.setFixedSize(1024, 768);
view.show();
}


Why ?

The main problem is that I need a GUI with an empty constructor as my main application will load a plugin (the GUI) that will create a GUI based on a QGraphicsScene.
So the Starter could create the QGraphicsScene and pass it to the gui class, but it doesn't work.

mcosta
28th October 2009, 14:33
IN the constructor of Starter you declare s into the
stack.
When the constructor exits, this instance is destroyed and
then your scene doesn't exists.

Try declaring s as member of Starter

trallallero
28th October 2009, 14:45
Thanks but no, doesn't work

mcosta
28th October 2009, 14:56
Sorry,

also the gui instance is destroyed when Starter constructor exits.
Then, also the gui instance must be a Starter Member

trallallero
28th October 2009, 15:08
Sorry,

also the gui instance is destroyed when Starter constructor exits.
Then, also the gui instance must be a Starter Member

Yes of course, I've seen it and I've just corrected it and it works.

Thanks a lot :)