Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Newbie QT question about connect

Tags:

c++

qt

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_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;
    }
}
like image 603
Tobias Langner Avatar asked Jan 17 '10 08:01

Tobias Langner


People also ask

What is connect in Qt?

This ensures that truly independent components can be created with Qt. You can connect as many signals as you want to a single slot, and a signal can be connected to as many slots as you need. It is even possible to connect a signal directly to another signal.

Is Qt easy to learn?

The overall development effort is minimal since Qt API are easy to understand and application functionality can be implemented with a smaller amount of code. C++ experts will find a lot of powerful APIs and tools in Qt which will make complicated things simple and new features easy to get done.

How signal and slot works in Qt?

The Qt signals/slots and property system are based on the ability to introspect the objects at runtime. Introspection means being able to list the methods and properties of an object and have all kinds of information about them such as the type of their arguments.

How do I get started with Qt?

Installing Qt. You can install the Qt Framework and tools by using an online or offline installer, or by building the source packages yourself. The installers allow you to download and install the following components: Qt libraries, prebuilt for a particular development platform (operating system and compiler)


1 Answers

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.

like image 189
mtvec Avatar answered Sep 18 '22 15:09

mtvec