Всем привет первый раз пишу консольное приложение на Qt
Никак не могу подцепить сигнал и слот помогите кто сталкивался с подобным
В функции start1 сокет не соединяется со слотом:
Ошибка:
Object::connect: No such slot QObject::slotReadDatagramm()Код:client.proQT += core network
QT -= gui
TARGET = consoleClient
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp \
client.cpp
HEADERS += \
client.h
main.cpp#include <QtCore/QCoreApplication>
#include "client.h"
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
if (argc < 2)
{
qDebug() << "ERROR: 111";
exit (1);
}
bool ok;
uint number = QString(argv [1]).toUInt(&ok);
if (!ok)
{
qDebug() << "ERROR: 222";
exit (2);
}
client clent(number);
clent.start1();
return a.exec();
}
client.h#ifndef CLIENT_H
#define CLIENT_H
#include <QObject>
class QUdpSocket;
class client: public QObject
{
public:
client(unsigned int number);
~client ();
void start1 ();
private:
unsigned int logicalNumber;
QUdpSocket * socket;
void processDatagramm (QByteArray datagramm);
public slots:
void slotReadDatagramm ();
void slotConnected ();
void slotDisconnect ();
};
#endif // CLIENT_H
client.cpp#include "client.h"
#include <QUdpSocket>
#include <QDateTime>
#include <QCoreApplication>
client::client(unsigned int number)
{
logicalNumber = number;
}
client::~client()
{
slotDisconnect();
}
void client::start1()
{
socket = new QUdpSocket ();
connect(socket,SIGNAL(readyRead()), this,SLOT(slotReadDatagramm()));
socket->connectToHost(QHostAddress::LocalHost,65000);
}
void client::slotConnected()
{
qDebug() << "Connected! IP: " + socket->localAddress().toString() + "; port: " + QString::number(socket->localPort());
unsigned char datagramm [3];
datagramm[0] = 0x01;
datagramm[1] = logicalNumber >> 8;
datagramm[2] = logicalNumber & 0xFF;
socket->write((char*)datagramm,3);
}
void client::slotDisconnect()
{
unsigned char datagramm [3];
datagramm[0] = 0x02;
datagramm[1] = logicalNumber >> 8;
datagramm[2] = logicalNumber & 0xFF;
socket->write((char*)datagramm,3);
}
void client::slotReadDatagramm()
{
while (socket->hasPendingDatagrams())
{
QByteArray datagramm;
datagramm.resize(socket->pendingDatagramSize());
QHostAddress sender;
quint16 prt;
socket->readDatagram(datagramm.data(),datagramm.size(),&sender,&prt);
processDatagramm(datagramm);
}
}
void client::processDatagramm(QByteArray datagramm)
{
if (datagramm.at(0) == 0x02)
{
exit(0);
}
else
{
qDebug () << QDateTime::currentDateTime().toString("dd.MM.yyyy hh.mm.ss") + ": Incoming message -" + QString(datagramm).toLatin1();
}
}