开发者

Newbie QT question about connect

开发者 https://www.devze.com 2022-12-17 03:03 出处:网络
I just tried to set up a small QT example and the connect statement fails to compile. the error message from the compiler is: \"no matching function for call to \'MainWindow::connect(...\'\"

I just tried to set up a small QT example and the connect statement fails to compile. the error message from the compiler is: "no matching function for call to 'MainWindow::connect(...'"

what am I doing wrong her?

Thank you for your help.

#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_authenti开发者_C百科cationRequired(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;
    }
}


QObject::connect expects pointers to QObject's, you are passing networkManager as a normal variable. Just changing connect(networkManager...) to connect(&networkManager...) should do the trick.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号