Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7092927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:22:32+00:00 2026-05-28T08:22:32+00:00

currently i am trying to laod *.obj-files into my programm. My code is based

  • 0

currently i am trying to laod *.obj-files into my programm. My code is based on this example:

Accelerate your widgets with OpenGL(changed link)

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 &) i call the function paintGL.

void OpenGLScene::drawBackground(QPainter *painter, const QRectF &)
{
    if (painter->paintEngine()->type() != QPaintEngine::OpenGL
    && painter->paintEngine()->type() != QPaintEngine::OpenGL2)
{
    qWarning("OpenGLScene: drawBackground needs a QGLWidget to be set as viewport on the graphics view");
    return;
}

painter->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->paintGL();
}

painter->endNativePainting();

}

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.

Here you can see my header-files: OpenGLScene.h and GLWidget.h:

class GLWidget : public QGLWidget
{
Q_OBJECT
public:
float           m_distance;
GLWidget(const QString &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<Point3d> m_points;
QVector<Point3d> m_normals;
QVector<int> m_edgeIndices;
QVector<int> m_pointIndices;
};


#ifndef QT_NO_CONCURRENT
#include <QFutureWatcher>
#endif

class GLWidget;

class OpenGLScene : public QGraphicsScene
{
Q_OBJECT

public:
OpenGLScene();
void drawBackground(QPainter *painter, const QRectF &rect);
QDialog *createDialog(const QString &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<GLWidget *> m_modelLoader;
#endif
public slots:
void loadModel();
void loadModel(const QString &filePath);
void modelLoaded();
};

Unfortunately this idea isnt working, because i get this error:

“It is not safe to use pixmaps outside the GUI thread”

But I really dont understand whats that supposed to mean.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:22:32+00:00Added an answer on May 28, 2026 at 8:22 am

    If you’ve moved all the Model stuff into GLWidget then I assume you are now creating your GLWidget instance in ::loadModel? If so then be aware that this is being created in a new thread. It looks like it doesn’t automatically get moved into the main (GUI) thread when the loading thread finishes. What actually happens to the QObject is an open question.

    If you want to disable threading completely in order to simplify things then remove the lines

    #ifndef QT_NO_CONCURRENT
    #include <QFutureWatcher>
    #endif
    

    and

    #ifndef QT_NO_CONCURRENT
    QFutureWatcher<Model *> m_modelLoader;
    #endif
    

    in openglscene.h. In the OpenGLScene constructor body remove the lines

    #ifndef QT_NO_CONCURRENT
        connect(&m_modelLoader, SIGNAL(finished()), this, SLOT(modelLoaded()));
    #endif
    

    In OpenGLScene::loadModel(const QString &filePath) change

    #ifndef QT_NO_CONCURRENT
        m_modelLoader.setFuture(QtConcurrent::run(::loadModel, filePath));
    #else
        setModel(::loadModel(filePath));
        modelLoaded();
    #endif
    

    to just

        setModel(::loadModel(filePath));
        modelLoaded();
    

    Finally remove

    #ifndef QT_NO_CONCURRENT
        setModel(m_modelLoader.result());
    #endif
    

    from OpenGLScene::modelLoaded().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to get into the Java EE development with the Spring framework.
I'm currently trying to pass a mono threaded program to multithread. This software do
I am currently trying to get the code coverage report for a PHP application
Im currently trying to save the tab.url into html5 local storage when the programme
I'm currently trying to develop a project based upon Firemonkey. I'm using Firemonkey for
I am currently trying to build some test code that uses Google C++ Test
i currently trying to view all the files and folder selected by the user
I'm currently trying to make some ajax post between cross-domains by following this tutorial
I currently trying to find a solution, how to ensure that a test fails
I'm currently trying to read in an XML file, make some minor changes (alter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.