gpt4 book ai didi

c++ - 关于connect的新手QT问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:26:08 25 4
gpt4 key购买 nike

我刚刚尝试设置一个小型 QT 示例,但连接语句无法编译。来自编译器的错误消息是:“没有匹配函数来调用 '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;
}
}

最佳答案

QObject::connect 需要指向 QObject 的指针,您将 networkManager 作为普通变量传递。只需将 connect(networkManager...) 更改为 connect(&networkManager...) 就可以解决问题。

关于c++ - 关于connect的新手QT问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2080405/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com