Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

pass data between qtquick controls (slider) and C++ application

$
0
0
Hello The issue is resolved now. Let me explain how I solved it. I have been following the documentation “Scene Graph – OpenGL Under QML” as a standard to adapt to my own project. According to it the renderer was initialized a bit later as follows: void Squircle::sync() {     if (!m_renderer) {         m_renderer = new SquircleRenderer();         connect(window(), SIGNAL(beforeRendering()), m_renderer, SLOT(paint()), Qt::DirectConnection);     }     m_renderer->setViewportSize(window()->size() * window()->devicePixelRatio());     m_renderer->setT(m_t); } In my project i did something similar as follows: void TessellationSceneItem::sync() {     if(!mTessScene)     {         //initialize the tessellation renderer         mTessScene = new TeapotTessellation();           //start tracking the time         mTIme.start();           //make the connection to render the opengl scene before the scene graph rendering         connect(window(),SIGNAL(beforeRendering()),mTessScene,SLOT(paint()),Qt::DirectConnection);           QTimer *timer = new QTimer();         connect(timer,SIGNAL(timeout()),this,SLOT(updateTime()),Qt::DirectConnection);         timer->start();     }           mTessScene->setViewportSize(window()->width() * window()->devicePixelRatio(),                                 window()->height() * window()->devicePixelRatio()); } But the the Qt’s Property System call the property setter and getter function right after the instantiation of the TessellationSceneItem, while the TeapotTessellation* mTessScene is not initialized yet. This is why i was getting the application crash. Now i moved the renderer class object instantiation inside the constructor of TessellationSceneItem as follows: TessellationSceneItem::TessellationSceneItem()     :mTessScene(0) {       //initialize the tessellation renderer     mTessScene = new TeapotTessellation();       //start tracking the time     mTIme.start();       QTimer *timer = new QTimer();     connect(timer,SIGNAL(timeout()),this,SLOT(updateTime()),Qt::DirectConnection);     timer->start();       connect(this,SIGNAL(windowChanged(QQuickWindow*)),this,SLOT(handleWindowChanged(QQuickWindow*)));   } Now I am encountering a new issue, i think it could be addressed in the same thread. The slider control inside the qml file has a property called “maximumValue” and it contains a value that depends on the opengl initialization of the underlying renderer class. class TessellationSceneItem : public QQuickItem {     Q_OBJECT    ......................    ......................     Q_PROPERTY(float maxPatchVertices READ maxPatchVertices CONSTANT)      .....................    ..................... }; Once the TessellationSceneItem is initialized the maxPatchVertices is called and it is containing the value 0 since by then the opengl initialization has not executed yet. How to deal with this issue. This “maxPatchVertices” contains the value for the slider value for “maximumValue” and “maxPatchVertices” comes from the opengl function     glGetIntegerv(GL_MAX_PATCH_VERTICES,&mMaxPatchVertices); The above function should return some value greater than 0 . I am getting 0 instead. Is there any way slider get the updated value in the qml side. The value remain constant in the qml side. Thats whay i have CONSTANT defined the peoperty definition. In a nutshell i would like to have the maximum vertices per patch to be assingned to the property maxPatchVertices and accessible in qml. I am not getting the correct one . Any hint to get it done ? Thanks

Viewing all articles
Browse latest Browse all 4972

Latest Images

Trending Articles



Latest Images