podsvirov / osgqtquick

Intergation OpenSceneGraph to Qt Quick
https://podsvirov.github.io/osgqtquick
MIT License
73 stars 32 forks source link

View doesn't work in a QQuickWidget #10

Open pm-ur opened 7 years ago

pm-ur commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

I agree that the project should help moving away from Qwidgets, but for existing applications it's usually not easy to convert to Qt quick in a single phase. For example, the application I'm working on is quite large and it may take almost a year's effort to port everything to Qt Quick. So, I plan to integrate and port UI components step-by-step.

Another thing I forgot to mention in my other email was that the project code is missing a license file. I guess it's LGPL (based on the entry at qtproject site) and LGPL works for us too. It would be great if you start including the license in the code root folder alongside cmakelists.txt file. This will maintain the license.

Regards, Piyoosh

On 03-Apr-2017 10:23 PM, "Konstantin Podsvirov" notifications@github.com wrote:

Hello @pm-energid https://github.com/pm-energid, thanks for your interest and experience!

I heard you. I had some experience in the experimental branch on my server http://git.podsvirov.pro/?p=openscenegraph/osgqtquick.git;a=shortlog;h=refs/heads/topic-school

  • 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.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/podsvirov/osgqtquick/issues/10#issuecomment-291203607, or mute the thread https://github.com/notifications/unsubscribe-auth/ANcM5Umy4kYe1kcxoSdmCIyjgzzmAnqzks5rsSP2gaJpZM4MxdXR .

pm-ur commented 7 years ago

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 commented 7 years ago

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

podsvirov commented 7 years ago

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

pm-ur commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

Hi Konstantin,

For some reason, windows and basic loop types aren't working properly on my system. I get just a black view and even other qml items don't render correctly as desired. I'll try to get some snapshots if possible.

Thanks, Piyoosh

On 06-Apr-2017 2:04 AM, "Konstantin Podsvirov" notifications@github.com wrote:

Hello @pm-energid https://github.com/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.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/podsvirov/osgqtquick/issues/10#issuecomment-291988031, or mute the thread https://github.com/notifications/unsubscribe-auth/ANcM5YsU3FvkrPBuJzHiti9pbmEcmJolks5rs_pygaJpZM4MxdXR .