qt - Add QML(QQuickView) to existing UI -


currently, developing qt class needs integrated in c++ visual studio project.

qt project - qt widgets application. build on qt creator 3.2.1 (opensource), based on qt 5.3.2. using visual studio 2013 professional, qt addin installed.

i tried solutions on internet or other stack posts without success. don't see post duplicate since other posts didn't solve problem.

i able run qml code, launches on different window. in first picture qml window (qt canvas) shown on program ui.

qml on separate window

i need integrate qml program ui. can use qgraphicsview if helps.

programui

simple qml example. canvas.qml

import qtquick 2.0 rectangle {     id: rectangle     color: "red"     width: 600     height: 600  } 

please have @ part of mvc implementation in project. here class visualize qml code in qt5.6. hope helps.

qmlviewbase::qmlviewbase( qwindow* parent, const std::string& qmlfilepath) {     this->m_pengine = qqmlengineptr( new qqmlengine() );     this->m_pview = qquickviewptr ( new qquickview( this->m_pengine.get(), parent ));     this->m_pview->setresizemode( qquickview::sizerootobjecttoview );     this->m_pview->setsource( qurl( qmlfilepath.c_str() ));     this->m_pview->setvisible( false );     this->m_pview->setminimumsize(qsize(640, 480)); }  qmlviewbase::~qmlviewbase() {     try {         this->m_pview.reset();     }catch(...) {      } }  void qmlviewbase::show() {     this->m_pview->show(); }  void qmlviewbase::hide() {     this->m_pview->hide(); }  bool qmlviewbase::isvisible() {     return this->m_pview->isvisible(); }  bool qmlviewbase::close() {     return this->m_pview->close(); }  qobject * const qmlviewbase::getslotssignalsobject() const {     return reinterpret_cast<qobject* const >( this->m_pview->rootobject() ); } 

to manage controllers have gui director class following implementation :

#ifndef de91_a97_4a2d_b906_01070cbfdd47 #define de91_a97_4a2d_b906_01070cbfdd47  #include "gui_director.h" #include "utility/event_handler/event_handler.h" #include "utility/exceptions.h" #include <boost/shared_ptr.hpp> #include <boost/weak_ptr.hpp> #include <map> #include <qapplication>  template<typename controllerid> class guidirectorimpl : public guidirector<controllerid>,                         public eventhandler<                               event<modeltouiparameters, servertoclienteventtype> > { public:    typedef boost::shared_ptr<guidirectorimpl<controllerid> > pointer;    typedef boost::weak_ptr<guidirectorimpl<controllerid> > weak_pointer;  public:    virtual ~guidirectorimpl()    {    }    ;    guidirectorimpl(qapplication *app)    {       m_app = app;       m_currentactivecontroller.reset();    }     virtual void addcontroller(controllerid controllerid,                               controller::pointer controller)    {       if (iscontrollerexist( controllerid )) {          boost_throw_exception( argument_error()                                 << error_description( "controller such id added" ) );       }        m_idtocontroller[controllerid] = controller;    }     virtual void setactive(controllerid controllerid)    {       if (!iscontrollerexist( controllerid )) {          boost_throw_exception( argument_error()                                 << error_description( "controller such id doesn't exeist" ) );       }        controller::pointer oldcontroller = m_currentactivecontroller;        m_currentactivecontroller = m_idtocontroller[controllerid];       if(null != oldcontroller)       {           oldcontroller->prepareviewtohide();       }       m_currentactivecontroller->prepareviewtoshow();        m_currentactivecontroller->startshowview();        if (null != oldcontroller) {          oldcontroller->stopshowview();       }    }     virtual void handleevent(event<modeltouiparameters, servertoclienteventtype>::pointer event_)    {       if (null == m_currentactivecontroller) {          boost_throw_exception( error()                                 << error_description( "no active controller, cant handle event" ) );       }        m_currentactivecontroller->handleevent( event_ );    }     virtual void quit()    {       m_app->quit();    }  private:    bool iscontrollerexist(controllerid controllerid)    {       typename std::map<controllerid, controller::pointer>::const_iterator iter = m_idtocontroller.find( controllerid );        if (m_idtocontroller.end() == iter) {          return false;       }        return true;    }  private:    qapplication *m_app;    controller::pointer m_currentactivecontroller;    typename std::map<controllerid, controller::pointer> m_idtocontroller; };  #endif /* de91_a97_4a2d_b906_01070cbfdd47 */ 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -