PDA

View Full Version : error unresolved externals



smemamian
30th March 2013, 12:57
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


#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "mynumber.h"
#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
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

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "mynumber.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ptr = new MyNumber(this);
connect(ptr,SIGNAL(numberChange(int)),this,SLOT(on eNumberChanged()));
}

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

#ifndef MYNUMBER_H
#define MYNUMBER_H

#include <QThread>

class MyNumber : public QThread
{
Q_OBJECT
public:
explicit MyNumber(QObject *parent = 0);
void run();
bool stop;


signals:
void numberChange(int);
public slots:

};

#endif // MYNUMBER_H


mynumber.cpp


#include "mynumber.h"
#include <QMutex>

MyNumber::MyNumber(QObject *parent) :
QThread(parent)
{
}

void MyNumber::run()
{
for (int i=0 ; i<1000 ; i++)
{
QMutex mutex ;
mutex.lock();
if(this->stop)
break;
mutex.unlock();

emit numberChange(i);
this->msleep(1);
}
}


Tnx

Santosh Reddy
30th March 2013, 13:03
Do a clean build

smemamian
30th March 2013, 13:25
very tnx.

but i click on start button :

8868

I get following errors:


QMutex: destroying locked mutex
:(

Maleesh
30th March 2013, 14:22
8868

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.

smemamian
30th March 2013, 15:34
what is a correct program solution ?
I'm confused.. :(
and i get this message :


QObject::connect: No such slot MainWindow::oneNumberChanged() in ..\20\mainwindow.cpp:12
QObject::connect: (receiver name: 'MainWindow')

Maleesh
30th March 2013, 15:59
what is a correct program solution ?
For that please do read some about mutex/locks.


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.

smemamian
30th March 2013, 16:45
I'm using this tutorial,plz look this address :

http://www.youtube.com/watch?v=PR6wVy7Et1A&list=SP2D1942A4688E9D63

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

Maleesh
31st March 2013, 04:24
I'm using this tutorial,plz look this address :

http://www.youtube.com/watch?v=PR6wVy7Et1A&list=SP2D1942A4688E9D63

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

OMG! Did you see that first comment for the video ? For mutex, see this (http://qt-project.org/doc/qt-4.8/qmutex.html#details) example in qt docs and this (http://stackoverflow.com/questions/6084110/trying-to-get-problems-with-qthread) question.

lunharis
18th July 2013, 13:23
I got the same error today.

QMutex: destroying locked mutex

ahmetkarakas
3rd September 2014, 07:54
you have to first set the stop parameter false.
Also write in start button clicked like this myThread -> stop =false; and than myThread -> start();