2 chenzelin1992 chenzelin1992 于 2016.03.11 14:49 提问

关于QTsocket Client客户端 进不去槽函数 1C

代码如下:
using namespace std;

Client::Client(QObject *parent) : QObject(parent)
{
connect(&client,SIGNAL(connected()), this, SLOT(startTransfer()));
connect(&client, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectError(QAbstractSocket::SocketError)));
connect(&client, SIGNAL(readyRead()), this, SLOT(startRead()));

}
Client::~Client()
{
client.close();
}

void Client::startTransferhandle(int chan,int val)
{
qDebug(">>>>>>>>>>>>>>>>>>>>>>>>");
qDebug()<<"chan:"<<chan<<"\t"<<"val:"<<val<<endl;
/*
QString setvalue = QString("%1:%2:%3").arg("SET").arg(chan).arg(val);
const char* str = qPrintable(setvalue);
// client.write(id ,13);
client.write(str);*/
}

void Client::start(QString address, quint16 port)
{
QHostAddress addr(address);
client.connectToHost(addr,port);
}

void Client::startTransfer()
{
CV = new ChanwithVal;
connect(CV, SIGNAL(sendATT(int,int)), this, SLOT(startTransferhandle(int,int)));
char error[100] = "connect success";
cout << error << endl;
client.write(error,100);
}

void Client::connectError(QAbstractSocket::SocketError)
{
char error[100] = "connect error";
cout << error << endl;
}

void Client::startRead()
{
char buffer[100] = {0};
client.read(buffer,client.bytesAvailable());
cout << "server say:" << buffer << endl;
client.close();
Client.h文件
class Client : public QObject
{
Q_OBJECT

public:
explicit Client(QObject* parent = 0);
~Client();
void start(QString address, quint16 port);

public slots:
void startTransfer();
void startRead();
void connectError(QAbstractSocket::SocketError);
private:
class ChanwithVal *CV;
QTcpSocket client;
// QString userStr;
private slots:
void startTransferhandle(int,int);
};
ChanwithVal.h文件
namespace Ui {
class ChanwithVal;
}

class ChanwithVal : public QDialog
{
Q_OBJECT

QPoint move_point;
bool mouse_press;

public:
explicit ChanwithVal(QWidget *parent = 0);
~ChanwithVal();
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);

signals:
void setATT(int, int, int);
void sendATT(int,int);

private:
Ui::ChanwithVal *ui;

ChanwithVal.cpp文件
ChanwithVal::ChanwithVal(QWidget *parent) :
QDialog(parent),
ui(new Ui::ChanwithVal)
{
ui->setupUi(this);
ui->spinBox_chan->setMaximum(4);
ui->spinBox_chan->setMinimum(1);
ui->spinBox_val->setMaximum(120);
ui->spinBox_val->setMinimum(0);
// ui->horizontalSlider_setAtt->setEnabled(false);

connect(ui->ChanButton_OK, SIGNAL(clicked()), this, SLOT(getChanAndVal()));
void ChanwithVal::getChanAndVal(void)
{
// QString qstr;

#ifdef DEBUGMODE
qDebug("Channel:%d, Value:%d", ui->spinBox_chan->value(), ui->spinBox_val->value());
qDebug("second window button clicked");
#endif
emit setATT(ui->spinBox_chan->value(), ui->spinBox_val->value(), 1);
emit sendATT(ui->spinBox_chan->value(), ui->spinBox_val->value());

1个回答

chenzelin1992
chenzelin1992   2016.03.11 14:51

CV = new ChanwithVal;
connect(CV, SIGNAL(sendATT(int,int)), this, SLOT(startTransferhandle(int,int)));进不去startTransferhandle(int,int)。没有打印信息。
新手求帮助

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!