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;
}
{
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
#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
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#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;
}
#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(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;
}
To copy to clipboard, switch view to plain text mode
mynumber.h
#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
#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
To copy to clipboard, switch view to plain text mode
mynumber.cpp
#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);
}
}
#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);
}
}
To copy to clipboard, switch view to plain text mode
Tnx
Bookmarks