2010-01-17 135 views
6

我只是試圖設置一個小的QT示例,並且connect語句無法編譯。 從編譯器的錯誤信息是:「爲號召不匹配函數‘的MainWindow ::連接(......’」關於連接的新手QT問題

我究竟做錯了她

謝謝你的幫助

#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; 
    } 
} 

回答

8

的QObject ::連接預計指針的QObject的,要傳遞NETWORKMANAGER作爲一個正常的變量,只是改變連接(NetworkManager的...)連接(& networkManager ...)應該做的伎倆。

+0

非常感謝。 –