linlinlinux1992 2016-03-11 06:49 采纳率: 0%
浏览 1568
已结题

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

代码如下:
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条回答 默认 最新

  • linlinlinux1992 2016-03-11 06:51
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?