Results 1 to 7 of 7

Thread: the qt class is not getting registered in qtquick

  1. #1
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default the qt class is not getting registered in qtquick

    Hello forum,

    i am registering a quickitem subclass object will the following command:

    Qt Code:
    1. qmlRegisterType<TessellationSceneItem>("TeapotTessellation",1,0,"TessellationSceneItem");
    To copy to clipboard, switch view to plain text mode 

    I should be seeing a rectangle with spring animation with mouse event and opengl scene as an underlay. I am only seeing the qml scene.

    I tried to set the breakpoint to the constructor of the qquickitem subclass that initiate the opengl rendering and i found out that the constructor is never executed.

    Any idea ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: the qt class is not getting registered in qtquick

    So is it that the class doesn't get registered or that it doesn't do what you thought it would? Do you get an error about an unexisting module when trying to import "TeapotTessellation" in your QML document? How about when you declare a TessellationSceneItem element (assuming the import worked).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: the qt class is not getting registered in qtquick

    Both , i guess. No i am not getting any error about an unexisting module when trying to import.

    OOps, my bad, now it is fine, the constructor is running. I have to decleare an element of the qquickitem type. Now i have something new. The application crashes with the following:

    Qt Code:
    1. QObject: Cannot create children for a parent that is in a different thread.
    2. (Parent is TessellationSceneItem(0x8153ea8), parent's thread is QThread(0x8080e08), current thread is QSGRenderThread(0x81d5db0)
    To copy to clipboard, switch view to plain text mode 

    And at the following point (glviewport(......)):

    Qt Code:
    1. void TeapotTessellation::resize(int w,int h)
    2. {
    3. if(h < 1)
    4. h = 1;
    5.  
    6. //set the viewport matrix
    7. ViewportMatrix = glm::mat4(glm::vec4((GLfloat)w/2.0f,0.0f,0.0f,0.0f),
    8. glm::vec4(0.0f,(GLfloat)h/2.0f,0.0f,0.0f),
    9. glm::vec4(0.0f,0.0f,1.0f,0.0f),
    10. glm::vec4((GLfloat)w/2.0f,(GLfloat)h/2.0f,0.0f,1.0f));
    11.  
    12. GLfloat aspect = w/(GLfloat)h;
    13.  
    14. //setup the projection matrix
    15. ProjectionMatrix = glm::perspective(50.0f,aspect,0.1f,1000.0f);
    16.  
    17. glViewport(0,0,w,h);
    18. }
    To copy to clipboard, switch view to plain text mode 

    Let me give you more code snippet:

    Qt Code:
    1. class TeapotTessellation;
    2.  
    3. class TessellationSceneItem : public QQuickItem
    4. {
    5. Q_OBJECT
    6.  
    7. Q_PROPERTY(float t READ t WRITE setT NOTIFY tChanged)
    8.  
    9. public:
    10. TessellationSceneItem();
    11.  
    12. qreal t() const { return m_t; }
    13. void setT(qreal t);
    14.  
    15. signals:
    16. void tChanged();
    17.  
    18. public slots:
    19. void sync();
    20. void cleanup();
    21.  
    22. private slots:
    23. void handleWindowChanged(QQuickWindow *);
    24.  
    25. private:
    26.  
    27. TeapotTessellation* mTessScene;
    28.  
    29. qreal m_t;
    30.  
    31. };
    32.  
    33. .......................
    34. .......................
    35.  
    36. #ifndef TEAPOTTESSELLATION_H
    37. #define TEAPOTTESSELLATION_H
    38.  
    39. #include <QOpenGLFunctions_4_3_Compatibility>
    40.  
    41. #include "defines.h"
    42. #include "AbstractScene.h"
    43.  
    44. class GLSLShader;
    45. class TeapotVboPatch;
    46.  
    47. class TeapotTessellation : public AbstractScene, protected QOpenGLFunctions_4_3_Compatibility
    48. {
    49. Q_OBJECT
    50.  
    51. public:
    52.  
    53. explicit TeapotTessellation(QObject *parent = 0);
    54. ~TeapotTessellation();
    55.  
    56. //scene related functions
    57. virtual void initialise();
    58. virtual void update(float t);
    59. virtual void render();
    60. virtual void resize(int w,int h);
    61.  
    62. public slots:
    63.  
    64. void paint();
    65.  
    66. private:
    67.  
    68. void loadShaders();
    69.  
    70. GLSLShader *mTessellationShader;
    71.  
    72. TeapotVboPatch *mTeapotPatch;
    73.  
    74. GLint mMaxPatchVertices;
    75.  
    76. GLfloat mInnerTessellationFactor;
    77.  
    78. GLfloat mOuterTessellationFactor;
    79.  
    80. glm::mat4 ModelViewMatrix;
    81. glm::mat4 ProjectionMatrix;
    82. glm::mat4 ViewportMatrix;
    83.  
    84. glm::mat4 ModelMatrix;
    85. glm::mat4 ViewMatrix;
    86.  
    87. glm::mat3 NormalMatrix;
    88.  
    89. float mTime;
    90.  
    91. float mZoom;
    92.  
    93. bool mInitialized;
    94. };
    95.  
    96. #endif // TEAPOTTESSELLATION_H
    To copy to clipboard, switch view to plain text mode 

    Let me know if you need more

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: the qt class is not getting registered in qtquick

    When do you instantiate TeapotTessellation? How exactly do you use it? What does your updatePaintNode() look like? You really have to provide more information, my crystal ball is broken.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: the qt class is not getting registered in qtquick

    Hi ,

    I have uploaded the source to the following repository:

    https://sajis997@bitbucket.org/sajis...negraphqml.git

    Please make some time to go through it.


    Thanks

    Hi ,

    I have uploaded the source to the following repository:

    https://sajis997@bitbucket.org/sajis...negraphqml.git

    Please make some time to go through it.


    Thanks


    Added after 1:


    Hi

    I managed to run the application. It does not crash anymore. But i still have following console output as before:

    Qt Code:
    1. QObject: Cannot create children for a parent that is in a different thread.
    2. (Parent is TessellationSceneItem(0x8153138), parent's thread is QThread(0x807fe08), current thread is QSGRenderThread(0x81d54f8)
    To copy to clipboard, switch view to plain text mode 

    While debuggin i found that i get the above console output with following connection snippet inside sync():

    Qt Code:
    1. void TessellationSceneItem::sync()
    2. {
    3. if(!mTessScene)
    4. {
    5. mTessScene = new TeapotTessellation(this);
    6.  
    7. connect(window(),SIGNAL(beforeRendering()),mTessScene,SLOT(paint()),Qt::DirectConnection);
    8. }
    9.  
    10. mTessScene->setViewportSize(window()->width() * window()->devicePixelRatio(),
    11. window()->height() * window()->devicePixelRatio());
    12.  
    13. //set the timer value from the qml to the mTessScene
    14. }
    To copy to clipboard, switch view to plain text mode 

    Any more thoughts ?

    Thanks
    Last edited by sajis997; 18th December 2014 at 02:13.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: the qt class is not getting registered in qtquick

    Line #5 of the snippet is certainly invalid. Assuming sync() is called from the rendering thread, you are creating a QObject instance and passing it a parent that lives in a different thread. To make the warning go away it is enough to not pass this as a parent. However you still access window's properties from the rendering thread which is what you shouldn't do.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: the qt class is not getting registered in qtquick

    Quote Originally Posted by wysota View Post
    Line #5 of the snippet is certainly invalid. Assuming sync() is called from the rendering thread, you are creating a QObject instance and passing it a parent that lives in a different thread. To make the warning go away it is enough to not pass this as a parent.
    Thanks the issue is resolved

    Quote Originally Posted by wysota View Post
    However you still access window's properties from the rendering thread which is what you shouldn't do.
    Did you mean the following snippet:

    Qt Code:
    1. mTessScene->setViewportSize(window()->width() * window()->devicePixelRatio(),
    2. window()->height() * window()->devicePixelRatio());
    To copy to clipboard, switch view to plain text mode 

    inside the sync() function . Let me tell you.... i followed the procedure narrated in the following qt documnentation :

    http://doc-snapshot.qt-project.org/q...l-example.html


    And it explained as follows:

    Note: The QQuickWindow::beforeSynchronizing() signal is emitted on the rendering thread while the GUI thread is blocked, so it is safe to simply copy the value without any additional protection.
    If you have some better suggestion get around with this issue, you are most welcome to refer me to any example/reference.

    I guess that issues never ends. Now i am having a white background color even after i am explicitly setting the background color to :


    Qt Code:
    1. //set the clearing color for the background
    2. glClearColor(0.5f,0.5f,0.5f,1.0f);
    To copy to clipboard, switch view to plain text mode 

    What could be the reason ? Since you have the reference to the repository , you will see that the rendering thread is functioning as follows:

    Qt Code:
    1. TeapotTessellation::TeapotTessellation(QObject *parent)
    2. : AbstractScene(parent),
    3. mTessellationShader(0),
    4. mTeapotPatch(0),
    5. mMaxPatchVertices(0),
    6. mInnerTessellationFactor(1.0f),
    7. mOuterTessellationFactor(1.0f),
    8. mZoom(22.0f),
    9. mInitialized(false)
    10. {
    11.  
    12. }
    13.  
    14. TeapotTessellation::~TeapotTessellation()
    15. {
    16. if(mTessellationShader)
    17. {
    18. mTessellationShader->DeleteShaderProgram();
    19. delete mTessellationShader;
    20. mTessellationShader = 0;
    21. }
    22.  
    23. if(mTeapotPatch)
    24. {
    25. delete mTeapotPatch;
    26. mTeapotPatch = 0;
    27. }
    28. }
    29.  
    30. void TeapotTessellation::initialise()
    31. {
    32.  
    33. //initialize the opengl functions
    34. initializeOpenGLFunctions();
    35.  
    36. loadShaders();
    37.  
    38. //initialize the teapot patch
    39. mTeapotPatch = new TeapotVboPatch(mTessellationShader);
    40.  
    41. //set the clearing color for the background
    42. glClearColor(0.5f,0.5f,0.5f,1.0f);
    43.  
    44. glGetIntegerv(GL_MAX_PATCH_VERTICES,&mMaxPatchVertices);
    45.  
    46. ModelViewMatrix = glm::mat4(1.0f);
    47. ProjectionMatrix = glm::mat4(1.0f);
    48. ViewportMatrix = glm::mat4(1.0f);
    49.  
    50. ViewMatrix = glm::mat4(1.0f);
    51. ModelMatrix = glm::mat4(1.0f);
    52.  
    53. NormalMatrix = glm::mat3(1.0f);
    54.  
    55. //enable depth testing
    56. glEnable(GL_DEPTH_TEST);
    57. glEnable(GL_CULL_FACE);
    58.  
    59. mInitialized = true;
    60.  
    61. }
    62.  
    63. void TeapotTessellation::loadShaders()
    64. {
    65. mTessellationShader = new GLSLShader();
    66.  
    67. mTessellationShader->LoadFromFile(GL_VERTEX_SHADER,"shaders/teapottessellation.vert");
    68. mTessellationShader->LoadFromFile(GL_TESS_CONTROL_SHADER,"shaders/teapottessellation.tcs");
    69. mTessellationShader->LoadFromFile(GL_TESS_EVALUATION_SHADER,"shaders/teapottessellation.tes");
    70. mTessellationShader->LoadFromFile(GL_GEOMETRY_SHADER,"shaders/teapottessellation.geom");
    71. mTessellationShader->LoadFromFile(GL_FRAGMENT_SHADER,"shaders/teapottessellation.frag");
    72.  
    73. mTessellationShader->CreateAndLinkProgram();
    74.  
    75. mTessellationShader->Use();
    76.  
    77. mTessellationShader->AddUniform("inner");
    78. mTessellationShader->AddUniform("outer");
    79. mTessellationShader->AddUniform("ModelviewMatrix");
    80. mTessellationShader->AddUniform("ProjectionMatrix");
    81. mTessellationShader->AddUniform("NormalMatrix");
    82. mTessellationShader->AddUniform("ViewportMatrix");
    83. mTessellationShader->AddUniform("Line.Width");
    84. mTessellationShader->AddUniform("Line.Color");
    85. mTessellationShader->AddUniform("Light.Position");
    86. mTessellationShader->AddUniform("Light.Intensity");
    87. mTessellationShader->AddUniform("Material.Kd");
    88. mTessellationShader->AddUniform("Material.Ka");
    89. mTessellationShader->AddUniform("Material.Ks");
    90. mTessellationShader->AddUniform("Material.Shininess");
    91.  
    92. //send the width of the line
    93. glUniform1f((*mTessellationShader)("Line.Width"),0.8f);
    94.  
    95. //define the color of the line
    96. glm::vec4 lineColor = glm::vec4(0.05f,0.0f,0.05f,1.0f);
    97.  
    98. //send the line color to the shader
    99. glUniform4fv((*mTessellationShader)("Line.Color"),1,glm::value_ptr(lineColor));
    100.  
    101. //define the light position
    102. glm::vec4 lightPosition = glm::vec4(0.25f,0.25f,1.0f,1.0f);
    103.  
    104. //send the light position to the shader
    105. glUniform4fv((*mTessellationShader)("Light.Position"),1,glm::value_ptr(lightPosition));
    106.  
    107. //define the light intensity
    108. glm::vec3 lightIntensity = glm::vec3(1.f,1.f,1.f);
    109.  
    110. //send the light intensity to the shader
    111. glUniform3fv((*mTessellationShader)("Light.Intensity"),1,glm::value_ptr(lightIntensity));
    112.  
    113. //now set and send the material property
    114.  
    115. glm::vec3 materialAmbientReflectivity = glm::vec3(0.2f,0.2f,0.2f);
    116.  
    117. glUniform3fv((*mTessellationShader)("Material.Ka"),1,glm::value_ptr(materialAmbientReflectivity));
    118.  
    119. glm::vec3 materialDiffuseReflectivity = glm::vec3(0.7f,0.7f,0.7f);
    120.  
    121. glUniform3fv((*mTessellationShader)("Material.Kd"),1,glm::value_ptr(materialDiffuseReflectivity));
    122.  
    123. glm::vec3 materialSpecularReflectivity = glm::vec3(0.8f,0.8f,0.8f);
    124.  
    125. glUniform3fv((*mTessellationShader)("Material.Ks"),1,glm::value_ptr(materialSpecularReflectivity));
    126.  
    127.  
    128. float materialShininess = 100.0f;
    129.  
    130. glUniform1f((*mTessellationShader)("Material.Shininess"),materialShininess);
    131.  
    132. mTessellationShader->UnUse();
    133. }
    134.  
    135. void TeapotTessellation::update(float t)
    136. {
    137. mTime = t;
    138. }
    139.  
    140. void TeapotTessellation::render()
    141. {
    142. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    143.  
    144. glm::mat4 Ty = glm::translate(glm::mat4(1.0f),glm::vec3(0.0f,1.5f,0.0f));
    145. glm::mat4 Tz = glm::translate(glm::mat4(1.0f),glm::vec3(0.0f,0.0f,-mZoom));
    146. glm::mat4 Ry = glm::rotate(glm::mat4(1.0),mTime,glm::vec3(0.0f,1.0f,0.0f));
    147. glm::mat4 Rx = glm::rotate(glm::mat4(1.0f),20.0f,glm::vec3(1.0f,0.0f,0.0f));
    148.  
    149. ModelMatrix = Tz * Ty * Ry * Rx;
    150.  
    151. ModelViewMatrix = ViewMatrix * ModelMatrix;
    152.  
    153. NormalMatrix = glm::inverseTranspose(glm::mat3(ModelViewMatrix));
    154.  
    155. mTessellationShader->Use();
    156.  
    157. glUniformMatrix4fv((*mTessellationShader)("ModelviewMatrix"),1,GL_FALSE,glm::value_ptr(ModelViewMatrix));
    158. glUniformMatrix4fv((*mTessellationShader)("ProjectionMatrix"),1,GL_FALSE,glm::value_ptr(ProjectionMatrix));
    159. glUniformMatrix4fv((*mTessellationShader)("ViewportMatrix"),1,GL_FALSE,glm::value_ptr(ViewportMatrix));
    160. glUniformMatrix3fv((*mTessellationShader)("NormalMatrix"),1,GL_FALSE,glm::value_ptr(NormalMatrix));
    161. glUniform1f((*mTessellationShader)("outer"),mOuterTessellationFactor);
    162. glUniform1f((*mTessellationShader)("inner"),mInnerTessellationFactor);
    163.  
    164. mTeapotPatch->render();
    165.  
    166. mTessellationShader->UnUse();
    167.  
    168. }
    169.  
    170. void TeapotTessellation::resize(int w,int h)
    171. {
    172. if(h < 1)
    173. mViewportHeight = 1;
    174.  
    175. mViewportWidth = w;
    176.  
    177. //set the viewport matrix
    178. ViewportMatrix = glm::mat4(glm::vec4((GLfloat)mViewportWidth/2.0f,0.0f,0.0f,0.0f),
    179. glm::vec4(0.0f,(GLfloat)mViewportHeight/2.0f,0.0f,0.0f),
    180. glm::vec4(0.0f,0.0f,1.0f,0.0f),
    181. glm::vec4((GLfloat)mViewportWidth/2.0f,(GLfloat)mViewportHeight/2.0f,0.0f,1.0f));
    182.  
    183. GLfloat aspect = w/(GLfloat)h;
    184.  
    185. //setup the projection matrix
    186. ProjectionMatrix = glm::perspective(50.0f,aspect,0.1f,1000.0f);
    187.  
    188. glViewport(0,0,mViewportWidth,mViewportHeight);
    189. }
    190.  
    191. void TeapotTessellation::setViewportSize(int width,int height)
    192. {
    193. mViewportWidth = width;
    194. mViewportHeight = height;
    195. }
    196.  
    197. void TeapotTessellation::paint()
    198. {
    199. if(!mInitialized)
    200. initialise();
    201.  
    202. resize(mViewportWidth,mViewportHeight);
    203. render();
    204. }
    To copy to clipboard, switch view to plain text mode 

    Thanks

Similar Threads

  1. qtquick application event handling from c++ class
    By nikhil.patil2010 in forum Qt Quick
    Replies: 1
    Last Post: 19th March 2014, 08:51
  2. Replies: 3
    Last Post: 6th March 2014, 10:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.