Results 1 to 2 of 2

Thread: Linking error: LNK2019 & LNK1120 - when creating/connecting a SIGNAL

  1. #1
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    37
    Thanks
    14
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Linking error: LNK2019 & LNK1120 - when creating/connecting a SIGNAL

    My goal here is to create a signal "expandParentItem" in my QFileSystemModel subclass so that when a parent item is checked in the associated QtreeView, the QtreeView can automatically expand it to show its children.
    I define and I emit the signal like this:

    FileSysSelectModel.h
    Qt Code:
    1. #ifndef FILESYSSELECTMODEL_H
    2. #define FILESYSSELECTMODEL_H
    3.  
    4. #include<QFileSystemModel>
    5. #include <QSet>
    6. #include <QPersistentModelIndex>
    7. #include <QVariant>
    8.  
    9. class FileSysSelectModel: public QFileSystemModel
    10. {
    11. private:
    12. QSet<QPersistentModelIndex> m_checkTable;
    13. QVariant m_noData;
    14.  
    15. void FileSysSelectModel::updateSubMembers(const QModelIndex &index, const QVariant &value);
    16.  
    17. public:
    18. int FileSysSelectModel::columnCount(const QModelIndex &parent) const;
    19. QVariant FileSysSelectModel::data(const QModelIndex &index, int role) const;
    20. virtual Qt::ItemFlags FileSysSelectModel::flags(const QModelIndex &index) const;
    21. virtual bool FileSysSelectModel::setData(const QModelIndex &index, const QVariant &value, int role);
    22.  
    23. signals:
    24. void expandParentItem(const QModelIndex &index);
    25. };
    26.  
    27. #endif // FILESYSSELECTMODEL_H
    To copy to clipboard, switch view to plain text mode 
    Function managing the signal in FileSysSelectModel.cpp
    Qt Code:
    1. //if the current item has children:
    2. // check all the child items if the parent item is checked.
    3. // uncheck all the child items if the parent item is unchecked.
    4. void FileSysSelectModel::updateSubMembers(const QModelIndex &index, const QVariant &value)
    5. {
    6. QModelIndex firstChild = index.child(0,0);
    7. QModelIndex currentChild;
    8. if (firstChild.isValid())
    9. {
    10. if(value == Qt::Checked) emit expandParentItem(index);
    11.  
    12. int i = 0;
    13. while(1)
    14. {
    15. currentChild = index.child(i,0);
    16. //Recursive call
    17. FileSysSelectModel::updateSubMembers(currentChild, value);
    18. if (!currentChild.isValid()) break;
    19. if(value == Qt::Checked) m_checkTable.insert(currentChild); else m_checkTable.remove(currentChild);
    20. i = i+1;
    21. }
    22. emit dataChanged(firstChild, currentChild);
    23. }
    24. }
    To copy to clipboard, switch view to plain text mode 
    I connect the signal to the QtreeView in my main window like this:

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9.  
    10. m_fileSystemModel = new FileSysSelectModel;
    11. m_fileSystemModel->setRootPath(QDir::currentPath());
    12. ui->scriptFileView->setModel(m_fileSystemModel);
    13.  
    14. QObject::connect(m_fileSystemModel,SIGNAL(expandParentItem(QModelIndex)),ui->scriptFileView,SLOT(expand(QModelIndex)));
    15. }
    16.  
    17. MainWindow::~MainWindow()
    18. {
    19. delete ui;
    20. }
    To copy to clipboard, switch view to plain text mode 

    When I try to compile, I get the following error message:

    FileSysSelectModel.obj:-1: error: LNK2019: unresolved external symbol "public: void __thiscall FileSysSelectModel::expandParentItem(class QModelIndex const &)" (?expandParentItem@FileSysSelectModel@@QAEXABVQMod elIndex@@@Z) referenced in function "private: void __thiscall FileSysSelectModel::updateSubMembers(class QModelIndex const &,class QVariant const &)" (?updateSubMembers@FileSysSelectModel@@AAEXABVQMod elIndex@@ABVQVariant@@@Z)

    debug\Designer_test.exe:-1: error: LNK1120: 1 unresolved externals

    I'm new to Qt and I'm having a hard time understanding this error message.
    Could someone help me with this issue?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,677
    Thanks
    13
    Thanked 1,596 Times in 1,524 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Linking error: LNK2019 & LNK1120 - when creating/connecting a SIGNAL

    You need the Q_OBJECT macro in the class declaration. You must rerun qmake after adding this macro.

    The code for signals (the bit your linker cannot find) is generated by moc, built and linked into your program courtesy of the Makefile qmake generates. These rules are triggered by the presence of the Q_OBJECT macro, which expands to include some support infrastructure for the Qt metaobject system and generated code.

  3. The following user says thank you to ChrisW67 for this useful post:

    Guett_31 (25th February 2013)

Similar Threads

  1. Replies: 2
    Last Post: 8th February 2013, 20:52
  2. Compilation Error LNK2019
    By Afandi in forum Newbie
    Replies: 3
    Last Post: 23rd December 2012, 16:14
  3. error LNK2019: unresolved external symbol
    By 8080205 in forum Newbie
    Replies: 3
    Last Post: 3rd October 2012, 16:53
  4. Replies: 5
    Last Post: 9th June 2011, 12:22
  5. Linking Error when Creating DLL with Visual Studio
    By stretchtiberius in forum Qt Programming
    Replies: 6
    Last Post: 10th February 2009, 20:31

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.