Results 1 to 10 of 10

Thread: error unresolved externals

  1. #1
    Join Date
    Mar 2013
    Posts
    45
    Thanks
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default error unresolved externals

    Hi
    I want to compile I get following errors:

    mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall MyNumber::MyNumber(class QObject *)" (??0MyNumber@@QAE@PAVQObject@@@Z) referenced in function "public: __thiscall MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QAE@PAVQWidget@@@Z)
    debug\20.exe:-1: error: LNK1120: 1 unresolved externals
    mainwindow.h

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3. #include "mynumber.h"
    4. #include <QMainWindow>
    5.  
    6. namespace Ui {
    7. class MainWindow;
    8. }
    9.  
    10. class MainWindow : public QMainWindow
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit MainWindow(QWidget *parent = 0);
    16. ~MainWindow();
    17. MyNumber *ptr ;
    18. public slots:
    19. void oneNumberChanged(int);
    20. private slots:
    21. void on_pushButton_clicked();
    22.  
    23. void on_pushButton_2_clicked();
    24.  
    25. private:
    26. Ui::MainWindow *ui;
    27. };
    28.  
    29. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include "mynumber.h"
    4.  
    5. MainWindow::MainWindow(QWidget *parent) :
    6. QMainWindow(parent),
    7. ui(new Ui::MainWindow)
    8. {
    9. ui->setupUi(this);
    10. ptr = new MyNumber(this);
    11. connect(ptr,SIGNAL(numberChange(int)),this,SLOT(oneNumberChanged()));
    12. }
    13.  
    14. MainWindow::~MainWindow()
    15. {
    16. delete ui;
    17. }
    18.  
    19. void MainWindow::oneNumberChanged(int number)
    20. {
    21. ui->label->setText(QString::number(number));
    22. }
    23. void MainWindow::on_pushButton_clicked()
    24. {
    25. ptr->start();
    26. }
    27.  
    28. void MainWindow::on_pushButton_2_clicked()
    29. {
    30. ptr->stop = true;
    31. }
    To copy to clipboard, switch view to plain text mode 

    mynumber.h
    Qt Code:
    1. #ifndef MYNUMBER_H
    2. #define MYNUMBER_H
    3.  
    4. #include <QThread>
    5.  
    6. class MyNumber : public QThread
    7. {
    8. Q_OBJECT
    9. public:
    10. explicit MyNumber(QObject *parent = 0);
    11. void run();
    12. bool stop;
    13.  
    14.  
    15. signals:
    16. void numberChange(int);
    17. public slots:
    18.  
    19. };
    20.  
    21. #endif // MYNUMBER_H
    To copy to clipboard, switch view to plain text mode 


    mynumber.cpp
    Qt Code:
    1. #include "mynumber.h"
    2. #include <QMutex>
    3.  
    4. MyNumber::MyNumber(QObject *parent) :
    5. QThread(parent)
    6. {
    7. }
    8.  
    9. void MyNumber::run()
    10. {
    11. for (int i=0 ; i<1000 ; i++)
    12. {
    13. QMutex mutex ;
    14. mutex.lock();
    15. if(this->stop)
    16. break;
    17. mutex.unlock();
    18.  
    19. emit numberChange(i);
    20. this->msleep(1);
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 

    Tnx

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: error unresolved externals

    Do a clean build
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

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

    smemamian (30th March 2013)

  4. #3
    Join Date
    Mar 2013
    Posts
    45
    Thanks
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: error unresolved externals

    very tnx.

    but i click on start button :

    Extern.gif

    I get following errors:

    QMutex: destroying locked mutex
    Last edited by smemamian; 30th March 2013 at 14:30.

  5. #4
    Join Date
    Mar 2010
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: error unresolved externals

    Quote Originally Posted by smemamian View Post

    Extern.gif

    I get following errors:
    There are only two places that your mutex getting destroyed,
    1. at the break
    2. at the end of iteration of the loop

    You could try to unlock it just before beaking the loop. Anyway the way you are using the mutex is not correct, because you are not considering to get a lock before setting stop attribute true. And you have to use the same mutex object at both places. Just by creating a mutex and lock it will not do anything. So, move mutex object to class attributes and lock it before accessing the stop attribute (in every place in you project) and release it afterward.
    Last edited by Maleesh; 30th March 2013 at 15:29.

  6. #5
    Join Date
    Mar 2013
    Posts
    45
    Thanks
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: error unresolved externals

    what is a correct program solution ?
    I'm confused..
    and i get this message :
    QObject::connect: No such slot MainWindow:neNumberChanged() in ..\20\mainwindow.cpp:12
    QObject::connect: (receiver name: 'MainWindow')

  7. #6
    Join Date
    Mar 2010
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: error unresolved externals

    Quote Originally Posted by smemamian View Post
    what is a correct program solution ?
    For that please do read some about mutex/locks.

    Quote Originally Posted by smemamian View Post
    and i get this message :
    It says what is the issue. There is no slot called "oneNumberChanged" which does not take any arguments. Try to use as "oneNumberChanged(int)" when connecting the slot.

  8. The following user says thank you to Maleesh for this useful post:

    smemamian (30th March 2013)

  9. #7
    Join Date
    Mar 2013
    Posts
    45
    Thanks
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: error unresolved externals

    I'm using this tutorial,plz look this address :

    http://www.youtube.com/watch?v=PR6wV...1942A4688E9D63

    c++ Qt 31 - QThread part 4 ...

  10. #8
    Join Date
    Mar 2010
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: error unresolved externals

    Quote Originally Posted by smemamian View Post
    I'm using this tutorial,plz look this address :

    http://www.youtube.com/watch?v=PR6wV...1942A4688E9D63

    c++ Qt 31 - QThread part 4 ...
    OMG! Did you see that first comment for the video ? For mutex, see this example in qt docs and this question.

  11. #9
    Join Date
    Jul 2013
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: error unresolved externals

    I got the same error today.

    QMutex: destroying locked mutex
    Last edited by lunharis; 18th July 2013 at 14:34.

  12. #10
    Join Date
    Sep 2014
    Posts
    1
    Qt products
    Qt3
    Platforms
    Windows

    Default Solution of the issue

    you have to first set the stop parameter false.
    Also write in start button clicked like this myThread -> stop =false; and than myThread -> start();

Similar Threads

  1. Replies: 17
    Last Post: 7th November 2010, 01:51
  2. Configuring Qt fow Wince (QtNetwork4.dll unresolved externals)
    By southerton in forum Installation and Deployment
    Replies: 0
    Last Post: 1st October 2010, 12:16
  3. Replies: 2
    Last Post: 31st October 2009, 04:41
  4. Unresolved externals
    By MarkoSan in forum General Programming
    Replies: 3
    Last Post: 17th March 2007, 14:53
  5. What am I missing? Unresolved externals
    By derick in forum Qt Programming
    Replies: 49
    Last Post: 21st July 2006, 13:41

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.