0

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

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Rubina
  • 123
  • 1
  • 17
  • **Error** Mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl QQuickWidget::~QQuickWidget(void)" (__imp_??1QQuickWidget@@UEAA@XZ) referenced in function "public: virtual void * __cdecl QQuickWidget::`scalar deleting destructor'(unsigned int)" (??_GQQuickWidget@@UEAAPEAXI@Z) – Rubina Apr 06 '18 at 03:02
  • .qml is in Resource folder – Rubina Apr 06 '18 at 03:04
  • QT += core gui qml quick greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = Sample TEMPLATE = app DEFINES += QT_DEPRECATED_WARNINGS #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 SOURCES += \ main.cpp \ mainwindow.cpp HEADERS += \ mainwindow.h FORMS += \ mainwindow.ui RESOURCES += \ resources.qrc – Rubina Apr 06 '18 at 03:24
  • You shall find the solution base on the error message. https://stackoverflow.com/questions/9928238/unresolved-external-symbol-in-object-files – JustWe Apr 06 '18 at 04:19

1 Answers1

3

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:

eyllanesc
  • 235,170
  • 19
  • 170
  • 241