在用QT编程时,建了一个自己的类,但是编译时出现错误,求教大侠们如何解决
错误提示为widgetshare.cpp:12:error:nomatchingfunctionforcallto'Widgetshare::connect(QTcpSe...
错误提示为widgetshare.cpp:12: error: no matching function for call to 'Widgetshare::connect(QTcpServer**, const char*, Widgetshare* const, const char*)',其中Widgetshare是我自己的类,类定义为//#ifndef WIDGETSHARE_H
#define WIDGETSHARE_H
#include <QtNetWork>
#include <QWidget>
#include <QTcpServer>
#include <QObject>
namespace Ui {
class Widget;
}
class Widgetshare : public QWidget
{
Q_OBJECT
public:
explicit Widgetshare(QWidget *parent = 0);
~Widgetshare();
private:
Ui::Widget *ui;
QTcpServer *tcpServer;
QTcpSocket *tcpServerConnection;
qint64 totalBytes; //存放总大小信息
qint64 bytesReceived; //已收到数据的大小
qint64 fileNameSize; //文件名的大小信息
QString fileName; //存放文件名
QFile *localFile; //本地文件
QByteArray inBlock; //数据缓冲区
private slots:
void on_startButton_clicked();
void start(); //开始监听
void acceptConnection(); //建立连接
void updateServerProgress(); //更新进度条,接收数据
void displayError(QAbstractSocket::SocketError socketError);
//显示错误
};
//#endif
WIDGETSHARE_H,出错的程序文件为
#include "widgetshare.h"
#include "ui_widgetshare.h"
#include <QObject>
Widgetshare::Widgetshare(QWidget *parent):
QWidget(parent),
ui(new Ui::Widget)
{
totalBytes = 0;
bytesReceived = 0;
fileNameSize = 0;
QObject::connect(&tcpServer,SIGNAL(newConnection()),this,SLOT(acceptConnection()));
//当发现新连接时发出newConnection()信号
}
时间比较紧,可以追加分 展开
#define WIDGETSHARE_H
#include <QtNetWork>
#include <QWidget>
#include <QTcpServer>
#include <QObject>
namespace Ui {
class Widget;
}
class Widgetshare : public QWidget
{
Q_OBJECT
public:
explicit Widgetshare(QWidget *parent = 0);
~Widgetshare();
private:
Ui::Widget *ui;
QTcpServer *tcpServer;
QTcpSocket *tcpServerConnection;
qint64 totalBytes; //存放总大小信息
qint64 bytesReceived; //已收到数据的大小
qint64 fileNameSize; //文件名的大小信息
QString fileName; //存放文件名
QFile *localFile; //本地文件
QByteArray inBlock; //数据缓冲区
private slots:
void on_startButton_clicked();
void start(); //开始监听
void acceptConnection(); //建立连接
void updateServerProgress(); //更新进度条,接收数据
void displayError(QAbstractSocket::SocketError socketError);
//显示错误
};
//#endif
WIDGETSHARE_H,出错的程序文件为
#include "widgetshare.h"
#include "ui_widgetshare.h"
#include <QObject>
Widgetshare::Widgetshare(QWidget *parent):
QWidget(parent),
ui(new Ui::Widget)
{
totalBytes = 0;
bytesReceived = 0;
fileNameSize = 0;
QObject::connect(&tcpServer,SIGNAL(newConnection()),this,SLOT(acceptConnection()));
//当发现新连接时发出newConnection()信号
}
时间比较紧,可以追加分 展开
2个回答
展开全部
Widgetshare::connect 改 QObject::connect
更多追问追答
追问
我用的就是QObject::connect 啊,不好使
追答
widgetshare.cpp:12: error: no matching function for call to
'Widgetshare::connect(QTcpServer**, const char*, Widgetshare* const, const char*)'
你没贴这部分出来吧
connect只有QObject::connect这个用法,有什么好不好使的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询