Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qt 5.0: Combining QML code in a QMainWindow-derived main window
Forum Updated to NodeBB v4.3 + New Features

Qt 5.0: Combining QML code in a QMainWindow-derived main window

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 4 Posters 8.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    danielbsig
    wrote on last edited by
    #1

    Hi,

    what is the preferred method of having a QMainWindow application window, but the UI in QML? I would really like to use the new MediaPlayer and the VideoSurface elements in QtQuick 2.0, I'm assuming I can't host such a qml file in a QDeclarativeView-based environment?

    Any pointers whatsoever would be highly appreciated.

    Regards,
    Daniel

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Babalas
      wrote on last edited by
      #2

      I ended up finding a class (somewhere) called QWindowContainer. Looks like this:

      QWindowContainer.h
      @class QWindowContainerPrivate;

      class Q_WIDGETS_EXPORT QWindowContainer : public QWidget
      {
      Q_OBJECT
      Q_DECLARE_PRIVATE(QWindowContainer)

      public:
      explicit QWindowContainer(QWidget *parent = 0, Qt::WindowFlags f = 0);
      ~QWindowContainer();

      void setWindow(QWindow *window);
      QWindow *window() const;
      

      protected:
      bool event(QEvent *ev);
      };@

      QWindowContainer.cpp
      @class QWindowContainerPrivate : public QWidgetPrivate
      {
      public:
      Q_DECLARE_PUBLIC(QWindowContainer)

      QWindowContainerPrivate() : window(0) { }
      ~QWindowContainerPrivate() { }
      
      QWindow *window;
      

      };

      QWindowContainer::QWindowContainer(QWidget *parent, Qt::WindowFlags flags)
      : QWidget(*new QWindowContainerPrivate, parent, flags)
      {
      }

      QWindowContainer::~QWindowContainer()
      {
      }

      void QWindowContainer::setWindow(QWindow *window)
      {
      Q_D(QWindowContainer);

      Q_ASSERT(window && !d->window);
      QWidget *tlw = QWidget::window();
      tlw->winId(); // make sure the tlw has a platform window
      window->setParent(tlw->windowHandle());
      window->setGeometry(geometry());
      d->window = window;
      

      }

      QWindow *QWindowContainer::window() const
      {
      Q_D(const QWindowContainer);
      return d->window;
      }

      bool QWindowContainer::event(QEvent *e)
      {
      Q_D(QWindowContainer);
      if (!d->window)
      return QWidget::event(e);

      QEvent::Type type = e->type();
      switch (type) {
      case QEvent::Show:
          d->window->show();
          break;
      case QEvent::Hide:
          d->window->hide();
          break;
      case QEvent::Move: {
          QMoveEvent *me = static_cast<QMoveEvent *>(e);
          d->window->setPosition(me->pos());
      }
          break;
      case QEvent::Resize: {
          QResizeEvent *re = static_cast<QResizeEvent *>(e);
          d->window->resize(re->size());
          break;
      }
      default:
          break;
      }
      
      return QWidget::event(e);
      

      }@

      Then you have some code that looks like
      @QMainWindow window;
      QQuickView* view = new QQuickView;
      QWindowContainer* container = new QWindowContainer;
      container->setWindow(view);
      window.setCentralWidget(container);@

      It has issues though. At the moment I can not get QAction global shortcuts to work if the focus is on QQuickView.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jens
        wrote on last edited by
        #3

        It is probably this one: https://codereview.qt-project.org/#change,41539
        Please let us know if you find other issues with it. The plan is to include it or something similar with 5.1

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Babalas
          wrote on last edited by
          #4

          That's the one. Discovered today that shortcuts for QAction don't work when the focus is on the QQuickItem. I have raised a question about it in another post.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            ronghester
            wrote on last edited by
            #5

            Hi There,

            I am trying to integrate this class in my program on window machine and getting link errors. Link errors are given below. Also I am unable to include qwidget_p.h file.

            Any clue??

            mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall QWindowContainer::setWindow(class QWindow *)" (_imp?setWindow@QWindowContainer@@QAEXPAVQWindow@@@Z) referenced in function "public: __thiscall MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QAE@PAVQWidget@@@Z)
            mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QWindowContainer::QWindowContainer(class QWidget *,class QFlags<enum Qt::WindowType>)" (_imp??0QWindowContainer@@QAE@PAVQWidget@@V?$QFlags@W4WindowType@Qt@@@@@Z) referenced in function "public: __thiscall MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QAE@PAVQWidget@@@Z)
            mainwindow.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall QWindowContainer::metaObject(void)const " (?metaObject@QWindowContainer@@UBEPBUQMetaObject@@XZ)
            mainwindow.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall QWindowContainer::qt_metacast(char const *)" (?qt_metacast@QWindowContainer@@UAEPAXPBD@Z)
            mainwindow.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall QWindowContainer::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@QWindowContainer@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
            mainwindow.obj : error LNK2001: unresolved external symbol "protected: virtual bool __thiscall QWindowContainer::event(class QEvent *)" (?event@QWindowContainer@@MAE_NPAVQEvent@@@Z)
            mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QWindowContainer::~QWindowContainer(void)" (_imp??1QWindowContainer@@UAE@XZ) referenced in function "public: virtual void * __thiscall QWindowContainer::`scalar deleting destructor'(unsigned int)" (??_GQWindowContainer@@UAEPAXI@Z)

            1 Reply Last reply
            0
            • B Offline
              B Offline
              Babalas
              wrote on last edited by
              #6

              In cmake I have this
              @INCLUDE_DIRECTORIES(
              ${Qt5Widgets_PRIVATE_INCLUDE_DIRS}
              )

              QT5_USE_MODULES(Gui Widgets OpenGL Xml Quick)
              @

              1 Reply Last reply
              0
              • R Offline
                R Offline
                ronghester
                wrote on last edited by
                #7

                I am building this using QTCreator (2.6.1) and not sure what is equivalent of $Qt5Widgets_PRIVATE_INCLUDE_DIRS

                I search but could not found this as a system variable. I guess I have to find out proper file in mkspecs?
                any help?

                I am also afraid : https://bugreports.qt-project.org/browse/QTBUG-26869

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  Babalas
                  wrote on last edited by
                  #8

                  I think it is just
                  @
                  QT += widget widget-private
                  @

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    ronghester
                    wrote on last edited by
                    #9

                    No Same errors.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved