Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View doesn't work in a QQuickWidget #10

Open
pm-ur opened this issue Apr 3, 2017 · 8 comments
Open

View doesn't work in a QQuickWidget #10

pm-ur opened this issue Apr 3, 2017 · 8 comments

Comments

@pm-ur
Copy link

pm-ur commented Apr 3, 2017

Hi,

I'm unable to add a view to a QML file shown in a QQuickWidget. It either crashes the application (by default, as it detects the renderloop type to be threaded), or it cannot render properly. I've tested only on windows. I guess the reason is because QQuickWidget has a different rendering loop than the ones supported by OsgQtQuick. In their implementation, threaded renderloop is actually disabled. It'd be wonderful if the support for QQuickWidget can be added.

Thanks,
Piyoosh

@podsvirov
Copy link
Owner

Hello @pm-energid, thanks for your interest and experience!

I heard you. I had some experience in the experimental branch on my server - the last 4 commits (the code worked once, but it's already out of date).

It's even a little funny. This project arose to get away from the Widgets...

I will try to study this issue in the near future and maybe find a solution.

@pm-ur
Copy link
Author

pm-ur commented Apr 3, 2017 via email

@pm-ur
Copy link
Author

pm-ur commented Apr 4, 2017

I found that it's possible to create a container widget with a QQuickView-like window embedded inside it. See http://www.ics.com/blog/combining-qt-widgets-and-qml-qwidgetcreatewindowcontainer for details. However, I'm trying to look into use of QQuickWidget that is already provided by Qt to host QML engine in a QWidget environment. It should have better interaction support (less limitations) than the method described in this blog.

@podsvirov
Copy link
Owner

Yes. I known. Code on my server(now rebased to develop branch) use this mechanizm (QWidget::createWindowContainer(...)).

@podsvirov
Copy link
Owner

@pm-energid, can you provide code example and your environment description to restore your issue.

@pm-ur
Copy link
Author

pm-ur commented Apr 4, 2017

Ok. I'm running Qt 5.6.1 on Windows 10 64-bit. I'm building 32-bit binaries (MSVC 2013 - x86). My Qt build is custom, but it shouldn't affect it as we don't modify anything related.

Here is the sample code that crashes:

// ------------------------- qmlSampleDlg.h ---------------------
#include <QtQuick/QQuickView>
#include <QtWidgets/QDialog>
#include <QtQuickWidgets/QQuickWidget>

namespace Ec
{
class QmlSampleDlg : public QDialog
{
   Q_OBJECT

   QQuickWidget *m_quickWidget;

public:

   /// Constructor
   /// @param[in] parent    Owning modal widget
   explicit QmlSampleDlg
      (
      QWidget* parent
      );

   /// Destructor
   ~QmlSampleDlg
      (
      );

};

// ----------------------------------- qmlSampleDlg.cpp --------------
#include "qmlSampleDlg.h"
#include <QtWidgets/QVBoxLayout>
#include <QtQml/QQmlEngine>
#include <QtCore/QProcessEnvironment>

using namespace Ec;

//-----------------------------------------------------------------------------
// Ec::QmlSampleDlg constructor
//-----------------------------------------------------------------------------
QmlSampleDlg::QmlSampleDlg
   (
   QWidget* parent
   ) :
   QDialog(parent),
   m_quickWidget(new QQuickWidget)
{
   setMinimumWidth(640);
   setMinimumHeight(480);
   setLayout(new QVBoxLayout);
   m_quickWidget->engine()->addImportPath("qml");
   m_quickWidget->setSource
      (
      QUrl::fromLocalFile
         (
         QProcessEnvironment::systemEnvironment().value("EC_TOOLKITS").append("/res/view.qml")
         )
      );
   layout()->addWidget(m_quickWidget);
}

//-----------------------------------------------------------------------------
// Ec::QmlSampleDlg destructor
//-----------------------------------------------------------------------------
QmlSampleDlg::~QmlSampleDlg
   (
   )
{
}

view.qml:

// Qt
import QtQuick 2.0
import QtQuick.Controls 1.0
import QtQuick.Window 2.0

// OpenSceneGraph
import osg 2.0 as OSG
// Core types
import osgGA 2.0 as OSGGA
// GUI Abstraction
import osgViewer 2.0 as OSGViewer

OSGViewer.View {
    // Default view size
   anchors.fill: parent
    // Set favorite camera manipulator
    cameraManipulator: OSGGA.OrbitManipulator {    }

    // Set scene for rendering
    sceneData: OSG.Geode {
        OSG.ShapeDrawable {
            color: Qt.rgba(1, 1, 0, 1)
            shape: OSG.Box {
                halfLengths: Qt.vector3d(0.5, 0.5, 0.5)
            }
        }
    }
}

Error messages:

QOpenGLFramebufferObject: Framebuffer incomplete attachment.
QOpenGLFramebufferObject: Framebuffer incomplete attachment.
QOpenGLFramebufferObject: Framebuffer incomplete attachment.
QOpenGLFramebufferObject: Framebuffer incomplete attachment.
QOpenGLFramebufferObject: Framebuffer incomplete, missing attachment.
Warning: detected OpenGL error 'invalid value' at after RenderBin::draw(..)

If I change the type of m_quickWidget from QQuickWidget to QQuickView and write:

QWidget* pContainer = createWindowContainer(m_quickWidget, this);
layout()->addWidget(pContainer);

in place of:

layout()->addWidget(m_quickWidget);

then it renders fine.

@podsvirov
Copy link
Owner

Hello @pm-energid, thanks for your code example.
In my experience osgQtQuick scripts can be run and don't crash in QQuickWidget when QSG_RENDER_LOOP environment variable is set to basic or windows (but print some warnings and it does not work smoothly). With QSG_RENDER_LOOP is threaded it's crash when start.
There is no final solution, but there is a ground for reflection.

@pm-ur
Copy link
Author

pm-ur commented Apr 6, 2017 via email

pm-ur pushed a commit to Energid/osgqtquick that referenced this issue Nov 9, 2018
MOC running on non-QObject headers

Closes podsvirov#10

See merge request energid/osgqtquick!9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants