Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-31064

QtQuick2 cannot co-work with QtQuick1

    XMLWordPrintable

Details

    Description

      I'm on Windows. I want to use QtQuick2 and QtQuick1 at the same time, because there are some features currently not available for QtQuick2 (transparent related problems)

      main.cpp
      #include <QtWidgets/QApplication>
      #include <QQmlEngine>
      #include <QtQml/QQmlComponent>
      #include <QQuickView>
      #include <QQmlContext>
      #include <QWidget>
      #include "quick1.h"
      
      int main(int argc, char *argv[])
      {
      	QApplication a(argc, argv);
      
      	QQuickView* win = new QQuickView();
      	win->setSource(QUrl::fromLocalFile("quick2.qml"));	
      	
      	QWidget *container = QWidget::createWindowContainer(win);	
      	container->setWindowFlags(Qt::Window);
      	container->resize(win->size());
      	container->show();
      
      	start_quick1_view(container);
      
      	return a.exec();
      }
      

      using QtQuick2 and QtQuick1 in a same .cpp may lead to compile error, so I put QtQuick1 in a seperate .cpp file.

      quick1.h
      #pragma once
      
      #include <QWidget>
      
      void start_quick1_view(QWidget* parent);
      
      quick1.cpp
      #include "quick1.h"
      #include <QtDeclarative/qdeclarative.h>
      #include <QtDeclarative/qdeclarativeview.h>
      
      void start_quick1_view(QWidget* parent)
      {
      	QDeclarativeView view0(parent);
      	view0.move(60, 80);
      	//view0.setWindowFlags(Qt::FramelessWindowHint);		
      	view0.setSource(QUrl::fromLocalFile("quick1.qml"));
      	view0.show();
      }
      

      Comment this line "view0.setWindowFlags(Qt::FramelessWindowHint);" will make the program throws exception. Using Qt::FramelessWindowHint will make the Quick1's view not visible.

      quick2.qml and quick1.qml is very simple:

      quick2.qml
      import QtQuick 2.0
      
      Rectangle {
      	width: 600
      	height: 480
      	color: "red"
      }
      
      quick1.qml
      import QtQuick 1.1
      
      Rectangle {
      	width: 480
      	height: 320
      	color: "green"
      }
      

      I'm using Qt5.1beta1 (downloaded at May 5th). I also faced the problem when I'm using Qt5.0.2 patched with https://codereview.qt-project.org/#change,44285

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              aalpert Alan Alpert
              weiyuemin weiyuemin
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes