Qt 没有合适的默认构造函数可用
本人最近写一个demo,程序有两个类:bdy_1和HttpGet。bdy_1中有一个成员是HttpGet的对象。下面是bdy_1和HttpGet的定义和构造函数:
HttpGet的定义:
class HttpGet : public QObject
{
Q_OBJECT
public:
HttpGet(QObject *parent);
//HttpGet();
~HttpGet();
bool downloadFile(QUrl&);
signals:
void done();
private slots:
void httpRequestFinished(int requestId, bool error);
void readResponseHeader(const QHttpResponseHeader &responseHeader);
void updateDateReadProgress(int bytesRead, int totalBytes);
void httpDone(bool error);
private:
QHttp *http;
QFile *file;
int httpGetId;
bool httpRequestAborted;
QString fileName;
};
HttpGet::HttpGet(QObject *parent)
: QObject(parent)
{
http = new QHttp(this);
connect(http, SIGNAL(done(bool)), this, SLOT(httpDone(bool)));
connect(http, SIGNAL(requestFinished(int ,bool)), this, SLOT(httpRequestFinished(int, bool)));
connect(http, SIGNAL(dataReadProgress(int,int)), this, SLOT(updateDataReadProgress(int,int)));
connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader&)), this, SLOT(readResponseHeader(const QHttpResponseHeader&)));
}
class bdy_1 : public QMainWindow
{
Q_OBJECT
public:
bdy_1(QWidget *parent = 0, Qt::WFlags flags = 0);
~bdy_1();
public slots:
void load();
private:
Ui::bdy_1Class ui;
public:
HttpGet httpGet;
};
bdy_1::bdy_1(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
httpGet = new HttpGet(this);
ui.setupUi(this);
connect(ui.downloadButton, SIGNAL(clicked()), this, SLOT(load()));
}
httpGet = new HttpGet(this);
#include "bdy_1.h"
#include <QtGui/QApplication>
#include <qtextcodec.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTextCodec *codec = QTextCodec::codecForName("System"); //获取系统编码
QTextCodec::setCodecForLocale(codec);
QTextCodec::setCodecForCStrings(codec);
QTextCodec::setCodecForTr(codec);
bdy_1 w;
w.show();
w.httpGet.downloadFile(QUrl("http://2.xp85.com/soft/小马激活工具_xp85.com.zip"));
return a.exec();
}