Porting lowenergyscanner example. [SOLVED]

  • I create QT Widgets Application. Include in projects the following files:

    Build it without errors.
    Then in mainwindow.cpp I add :

    void MainWindow::on_pushButtonScan_clicked()
    QBluetoothDeviceDiscoveryAgent discoveryAgent = new BluetoothDeviceDiscoveryAgent();

    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?

  • Qt Champions 2016

    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.
    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 

  • Thank you very much. It solved the problem.

  • Qt Champions 2016

    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.

  • Qt Champions 2016

    @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.

  • I see. Thank you.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.