Note that there are some explanatory texts on larger screens.

plurals
  1. POLoading files into drawBackground(QPainter *painter, const QRectF &)
    primarykey
    data
    text
    <p>currently i am trying to laod *.obj-files into my programm. My code is based on this example:</p> <p><a href="http://qt.gitorious.org/qt-labs/modelviewer" rel="nofollow">Accelerate your widgets with OpenGL(changed link)</a></p> <p>The only differeence in my code, is that i have a glwidget-class, in which all the drawing is defined. In the class OpenGLScene only my Gui is defined. In the function drawBackground(QPainter *painter, const QRectF &amp;) i call the function paintGL.</p> <pre><code>void OpenGLScene::drawBackground(QPainter *painter, const QRectF &amp;) { if (painter-&gt;paintEngine()-&gt;type() != QPaintEngine::OpenGL &amp;&amp; painter-&gt;paintEngine()-&gt;type() != QPaintEngine::OpenGL2) { qWarning("OpenGLScene: drawBackground needs a QGLWidget to be set as viewport on the graphics view"); return; } painter-&gt;beginNativePainting(); glClearColor(m_backgroundColor.redF(), m_backgroundColor.greenF(), m_backgroundColor.blueF(), 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (m_model) { m_model-&gt;paintGL(); } painter-&gt;endNativePainting(); </code></pre> <p>}</p> <p>Simple drawing and stuff works fine. I only get problems until i try to load *.obj-Files. I have tried several things, which didnt work. Now I ended up with the solution to define all the functions from the model-class(which you can find in the example) in my glWidget-Class and then calling the render-function in paintGL. Afterwards calling the paintGL in OpenGLScene.</p> <p>Here you can see my header-files: OpenGLScene.h and GLWidget.h:</p> <pre><code>class GLWidget : public QGLWidget { Q_OBJECT public: float m_distance; GLWidget(const QString &amp;filePath); GLWidget(QWidget *parent = 0); ~GLWidget(); QSize minimumSizeHint() const; QSize sizeHint() const; void initializeGL(); void paintGL(); void resizeGL(int width, int height); void render() const; QString fileName() const { return m_fileName; } int faces() const { return m_pointIndices.size() / 3; } int edges() const { return m_edgeIndices.size() / 2; } int points() const { return m_points.size(); } QString m_fileName; QVector&lt;Point3d&gt; m_points; QVector&lt;Point3d&gt; m_normals; QVector&lt;int&gt; m_edgeIndices; QVector&lt;int&gt; m_pointIndices; }; #ifndef QT_NO_CONCURRENT #include &lt;QFutureWatcher&gt; #endif class GLWidget; class OpenGLScene : public QGraphicsScene { Q_OBJECT public: OpenGLScene(); void drawBackground(QPainter *painter, const QRectF &amp;rect); QDialog *createDialog(const QString &amp;windowTitle) const; void setModel(GLWidget *model); //Model *m_model; GLWidget *m_model; QColor m_backgroundColor; float m_distance; QLabel *m_labels[4]; QWidget *m_modelButton; #ifndef QT_NO_CONCURRENT QFutureWatcher&lt;GLWidget *&gt; m_modelLoader; #endif public slots: void loadModel(); void loadModel(const QString &amp;filePath); void modelLoaded(); }; </code></pre> <p>Unfortunately this idea isnt working, because i get this error:</p> <p>"It is not safe to use pixmaps outside the GUI thread"</p> <p>But I really dont understand whats that supposed to mean.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload