PDA

View Full Version : An extremely noob question about QtQuick viewer implementation???



Zingam
24th October 2012, 15:28
I am looking at how the qml viewer (for 4.8 and 5.0) is implemented. And I wonder why is it so.

In the .h(eader) we have:



class QtQuick2ApplicationViewer : public QQuickView
{
Q_OBJECT

...

private:
class QtQuick2ApplicationViewerPrivate *d;
};

Then in the .CPP file:


class QtQuick2ApplicationViewerPrivate
{
QString mainQmlFile;
friend class QtQuick2ApplicationViewer;
static QString adjustPath(const QString &path);
};

QtQuick2ApplicationViewer::QtQuick2ApplicationView er(QWindow *parent)
: QQuickView(parent)
, d(new QtQuick2ApplicationViewerPrivate())
{
connect(engine(), SIGNAL(quit()), SLOT(close()));
setResizeMode(QQuickView::SizeRootObjectToView);

#ifdef Q_OS_ANDROID
engine()->setBaseUrl(QUrl::fromLocalFile("/"));
#endif
}

So I have basically two questions.
(1) The first one about the friend class. Why is it necessary. I don't see any reason why would anybody use a friend class. Is there any real use for friend classes (except for exotics that anybody could live without)?

(2) The second one is: connect(engine(), SIGNAL(quit()), SLOT(close())); Isn't quit() defined as slot? How is it a signal here? Is it wrong to use quit() instead of close()? connect(engine(), SIGNAL(quit()), SLOT(quit()));

Le_B
25th October 2012, 09:19
1 - i can't really answer this but this implementation is done in all QT class i think.

2 - the quit signal is from the engine not the viewer, so if the engine says i m off the view cannot do much and has to quit to avoid problems