How to add Switch Qml to qt widgets?

868 Views Asked by At

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

1

There are 1 best solutions below

7
On BEST ANSWER

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: