error unresolved externals
Hi
I want to compile I get following errors:
Quote:
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)
Quote:
debug\20.exe:-1: error: LNK1120: 1 unresolved externals
mainwindow.h
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "mynumber.h"
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
MyNumber *ptr ;
public slots:
void oneNumberChanged(int);
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "mynumber.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
ptr = new MyNumber(this);
connect(ptr,SIGNAL(numberChange(int)),this,SLOT(oneNumberChanged()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::oneNumberChanged(int number)
{
ui
->label
->setText
(QString::number(number
));
}
void MainWindow::on_pushButton_clicked()
{
ptr->start();
}
void MainWindow::on_pushButton_2_clicked()
{
ptr->stop = true;
}
mynumber.h
Code:
#ifndef MYNUMBER_H
#define MYNUMBER_H
#include <QThread>
{
Q_OBJECT
public:
explicit MyNumber
(QObject *parent
= 0);
void run();
bool stop;
signals:
void numberChange(int);
public slots:
};
#endif // MYNUMBER_H
mynumber.cpp
Code:
#include "mynumber.h"
#include <QMutex>
MyNumber
::MyNumber(QObject *parent
) :{
}
void MyNumber::run()
{
for (int i=0 ; i<1000 ; i++)
{
mutex.lock();
if(this->stop)
break;
mutex.unlock();
emit numberChange(i);
this->msleep(1);
}
}
Tnx
Re: error unresolved externals
1 Attachment(s)
Re: error unresolved externals
very tnx.
but i click on start button :
Attachment 8868
I get following errors:
Quote:
QMutex: destroying locked mutex
:(
Re: error unresolved externals
Quote:
Originally Posted by
smemamian
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.
Re: error unresolved externals
what is a correct program solution ?
I'm confused.. :(
and i get this message :
Quote:
QObject::connect: No such slot MainWindow::oneNumberChanged() in ..\20\mainwindow.cpp:12
QObject::connect: (receiver name: 'MainWindow')
Re: error unresolved externals
Quote:
Originally Posted by
smemamian
what is a correct program solution ?
For that please do read some about mutex/locks.
Quote:
Originally Posted by
smemamian
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.
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 ...
Re: error unresolved externals
Quote:
Originally Posted by
smemamian
OMG! Did you see that first comment for the video ? For mutex, see this example in qt docs and this question.
Re: error unresolved externals
I got the same error today.
QMutex: destroying locked mutex