简体   繁体   中英

How to add Switch Qml to qt widgets?

I have a qml file ToggleSwitch.qml which I want to import to my widgets. Basically I want to integrate qml with widget

ToggleSwitch.qml

Switch  
{  
    checked:true  
} 

In Mainwindow.cpp I want do something like this

Mainwindow.cpp

QQuickWidget *quickWidget = new QQuickWidget;   
quickWidget->setSource(QUrl("qrc:/Resources/ToggleSwitch.qml"));  
QVBoxLayout *vBox = new QVBoxLayout;  
vBox->addWidget(quickWidget); 

I tried this above code but it does not work. It throws error unresolved external symbol

To use QQuickWidget you must add the module quickwidgets , add the following to the .pro:

QT += quickwidgets

Also do not forget to include the header:

#include <QQuickWidget>

If you are in windows you must use windowdeployqt to obtain all the necessary dlls to execute your application, more information the following link:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM