关于连接的新手QT问题

时间:2010-01-17 08:22:09

标签: c++ qt

我只是尝试设置一个小的QT示例,并且connect语句无法编译。 来自编译器的错误消息是:“没有用于调用'MainWindow :: connect(...'”

的匹配函数

我做错了什么?

感谢您的帮助。

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QNetworkAccessManager>
#include <QNetworkReply>

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow {
    Q_OBJECT
public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

protected:
    void changeEvent(QEvent *e);

private:
    Ui::MainWindow *ui;
    QNetworkAccessManager networkManager;

private slots:
    void on_requestButton_clicked();
    void on_authenticationRequired(QNetworkReply* reply, QAuthenticator* auth);
    void on_finished(QNetworkReply* reply);
};

#endif // MAINWINDOW_H

#include "mainwindow.h"
#include "ui_mainwindow.h"

void MainWindow::on_requestButton_clicked()
{

}

void MainWindow::on_authenticationRequired(QNetworkReply* reply, QAuthenticator* auth)
{

}

void MainWindow::on_finished(QNetworkReply* reply)
{

}

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow), networkManager(this)
{
    ui->setupUi(this);
    connect(networkManager, SIGNAL(finished(QNetworkReply*)),
            this, SLOT(on_finished(QNetworkReply*)));
    connect(networkManager,SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)),
            this, SLOT(on_authenticationRequired(QNetworkReply*,QAuthenticator*)));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::changeEvent(QEvent *e)
{
    QMainWindow::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

1 个答案:

答案 0 :(得分:8)

QObject :: connect需要指向QObject的指针,您将networkManager作为普通变量传递。只需将连接(networkManager ...)更改为连接(&amp; networkManager ...)即可。