Porting lowenergyscanner example. [SOLVED]
-
I create QT Widgets Application. Include in projects the following files:
device.cpp
deviceinfo.cpp
serviceinfo.cpp
characteristicinfo.cpp
device.h
deviceinfo.h
serviceinfo.h
characteristicinfo.hBuild it without errors.
Then in mainwindow.cpp I add :void MainWindow::on_pushButtonScan_clicked()
{
QBluetoothDeviceDiscoveryAgent discoveryAgent = new BluetoothDeviceDiscoveryAgent();
discoveryAgent.start();
}But when I build I get some errors:
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent(class QObject *)" (_imp??0QBluetoothDeviceDiscoveryAgent@@QAE@PAVQObject@@@Z) referenced in function "private: void __thiscall MainWindow::on_pushButtonScan_clicked(void)" (?on_pushButtonScan_clicked@MainWindow@@AAEXXZ)
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QBluetoothDeviceDiscoveryAgent::~QBluetoothDeviceDiscoveryAgent(void)" (_imp??1QBluetoothDeviceDiscoveryAgent@@UAE@XZ) referenced in function "public: virtual void * __thiscall QBluetoothDeviceDiscoveryAgent::`scalar deleting destructor'(unsigned int)" (??_GQBluetoothDeviceDiscoveryAgent@@UAEPAXI@Z)
mainwindow.obj:-1: error: LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall QBluetoothDeviceDiscoveryAgent::metaObject(void)const " (?metaObject@QBluetoothDeviceDiscoveryAgent@@UBEPBUQMetaObject@@XZ)
mainwindow.obj:-1: error: LNK2001: unresolved external symbol "public: virtual int __thiscall QBluetoothDeviceDiscoveryAgent::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@QBluetoothDeviceDiscoveryAgent@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
What’s wrong with my code?
-
QT += bluetooth
-
Is it supposed to mean something?
-
@jenya7
Yes it means, open the .pro file (the project file)
and insert that line on top
It adds the module called bluetooth
Often it already adds gui that way.
like
QT += core gui
so you just add it to the line (only bluetooth)
or on its own line with full syntax as he wrote.small note:
QBluetoothDeviceDiscoveryAgent *discoveryAgent = new BluetoothDeviceDiscoveryAgent(); discoveryAgent.start(); <<-- should be discoveryAgent->start();
-
Thank you very much. It solved the problem.
-
@jenya7
super.
Now we just hope it actually discovers some devices :) -
Actually when I run the original example, and click the Search button it informs me - An unknown error has occurred.
-
@jenya7 said:
An unknown error has occurred.
Well you do have bluetooth in pc you run it on ?
ahh. it doesn't support windows at all.
https://forum.qt.io/topic/46338/bluetooth-device-discovery-not-working/3 -
I see. Thank you.