[Solved] SetContextProperty();
- #include "funzioni.h"
- #include <QDeclarativeContext>
- #include <QUrl>
- #include <QObject>
- #include <QGraphicsObject>
- #include <QDirectPainter>
- Funzioni::Funzioni()
- {
- view.rootContext()->setContextProperty("funzioni", this);
- #if defined(Q_WS_SIMULATOR) || defined(Q_OS_SYMBIAN)
- view.showFullScreen();
- #else
- view.show();
- #endif
- }
- int Funzioni::getHeight()
- {
- return QDirectPainter::screenHeight();
- }
- int Funzioni::getWidth()
- {
- return QDirectPainter::screenWidth();
- }
what must i use instead of this “view.rootContext()->setContextProperty(“funzioni”, this);”? instead of “this”…
10 replies
- #include "funzioni.h"
- #include <QDirectPainter>
- #include <QDeclarativeContext>
- #include <QGraphicsObject>
- {
- QDeclarativeView view;
- view.rootContext()->setContextProperty("funzioni", this);
- #if defined(Q_WS_SIMULATOR) || defined(Q_OS_SYMBIAN)
- view.showFullScreen();
- #else
- view.show();
- #endif
- }
- int Funzioni::getHeight()
- {
- return QDirectPainter::screenHeight();
- }
- int Funzioni::getWidth()
- {
- return QDirectPainter::screenWidth();
- }
0k, now errors are:
“error: undefined reference to `_imp___ZN14QDirectPainter12screenHeightEv’”
“error: undefined reference to `_imp___ZN14QDirectPainter11screenWidthEv’”
i am using windows 7. i used
- int Funzioni::getHeight()
- {
- return v->height();
- }
- int Funzioni::getWidth()
- {
- return c->width();
- }
but errors are: “TypeError: Result of expression ‘funzioni.getHeight’ [undefined] is not a function.” if i call methods by qml:
- import QtQuick 1.0
- Item
- {
- id: contenitore
- width: funzioni.getWidth();
- height: funzioni.getHeight();
- Image
- {
- source: "../LebendigeLieder/sfondo.jpg"
- anchors.top: contenitore.top
- anchors.left: contenitore.left
- id: sfondo
- z: -1
- }
- Rectangle
- {
- color:"red"
- width: 130; height: 30
- anchors.top: contenitore.top; anchors.right: contenitore.right
- radius: 10
- }
- }
Methods called from QML have to be either declared as slots or as Q_INVOKABLE [doc.qt.nokia.com].
What do you want to achieve? Display your application fullscreen?
Just use QDeclarativeView::setResizeMode [doc.qt.nokia.com].
basically, my issue is that i would a fullscreen application, but the root conteiner is so small that it cannot contain the rettangle. in fact, it is viewed as white rettangle which fills the width and the total height of the screen… i noted the general container is too small seing the QML designer…
solved with simple code:
- import QtQuick 1.0
- Rectangle {
- color: "orange"
- id: container
- Rectangle
- {
- id: indicatore
- anchors.right: container.right
- width: 130; height: 60
- }
- }
and
- #include <QtGui/QApplication>
- #include "qmlapplicationviewer.h"
- int main(int argc, char *argv[])
- {
- QmlApplicationViewer viewer;
- viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait);
- viewer.showExpanded();
- return app.exec();
- }
Be aware that if you are using QDeclarativeView::showFullscreen() you will need to set the geometry manually, otherwise your view won’t show up. In addition, the order is important:
- set the source
- set the resize mode
- set the geometry
- show
- int main(int argc, char* argv[])
- {
- view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
- view.setGeometry(application.desktop()->screenGeometry());
- view.showFullScreen();
- return(application.exec());
- }
- Rectangle {
- color: "green"
- }
You must log in to post a reply. Not a member yet? Register here!




