вот файл про
C++ (Qt)
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
QT += core gui network
TARGET = testAdam
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
my_thead.cpp
HEADERS += mainwindow.h \
my_thead.h
FORMS += mainwindow.ui
вот файл потока
C++ (Qt)
#include "my_thead.h"
XClientThread::XClientThread(QTcpSocket * sock,QObject *parent) : QThread(parent)
{
this->ok = true;
this->sock = sock;
start();
}
void XClientThread::setRecvOk()
{
char data [] = {0x1,0x8,0x5,0xE7,0xC3};
while(1)
{
if (ok)
{
tcpSocket->write(data);
ok = false;
}
}
}
void XClientThread::run(){
}
XClientThread::~XClientThread(){
exit();
wait();
}
вот файл cpp
C++ (Qt)
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
tcpSocket = new QTcpSocket();
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readSocket()));
tcpSocket->connectToHost(ui->lineEdit->text(),ui->spinBox->value());
if (!tcpSocket->waitForConnected()) {
QMessageBox::about(0,"QTcpSocket","Соеденение не установленно");
return;
}
ui->pushButton->setEnabled(false);
ui->pushButton_2->setEnabled(true);
}
void MainWindow::readSocket()
{
array = tcpSocket->readAll();
ui->plainTextEdit->appendPlainText(array.toHex().toUpper());
}
void MainWindow::on_pushButton_2_clicked()
{
tcpSocket->disconnectFromHost();
tcpSocket->close();
ui->pushButton->setEnabled(true);
ui->pushButton_2->setEnabled(false);
}
void MainWindow::on_pushButton_3_clicked()
{
xClientThread = new XClientThread(tcpSocket,this);
// char data [] = {0x1,0x8,0x5,0xE7,0xC3};
// tcpSocket->write(data);
}
Линкер ругается
mainwindow.obj:-1: ошибка: LNK2019: ссылка на неразрешенный внешний символ "public: __thiscall XClientThread::XClientThread(class QTcpSocket *,class QObject *)" (??0XClientThread@@QAE@PAVQTcpSocket@@PAVQObject@@@Z) в функции "private: void __thiscall MainWindow::on_pushButton_3_clicked(void)" (?on_pushButton_3_clicked@MainWindow@@AAEXXZ)