Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QT no matching function for call to 'MainWindow::connect()

Tags:

function

qt

I have MainWindow and QNAMRedirect classes and I am trying to compile program but getting compiler error.

Here is QNAMRedirect class:

class QNAMRedirect :  public QObject
{
    Q_OBJECT
public:
    explicit QNAMRedirect(QObject *parent = 0);
    ~QNAMRedirect();

signals:

public slots:
    void doRequest();
    void replyFinished(QNetworkReply* reply);
signals:
    void finished(QString);

private:
        QPointer<QNetworkAccessManager> _qnam;
        QUrl _originalUrl;
        QUrl _urlRedirectedTo;
        QNetworkAccessManager* createQNAM();

};

and here is MainWindow class:

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void on_request_clicked();

private:
    Ui::MainWindow *ui;
};

and i am trying to connect NAMRedirect::finished(QString) signal to QTextEdit widget in MainWindow this way:

    void MainWindow::on_request_clicked()
{
    QNAMRedirect urlGet(this);
    QObject::connect(urlGet,SIGNAL(finished(QString)),ui->textEdit,SLOT(setText(QString)));

    urlGet.doRequest();

}

but i am getting compiler error:

error: no matching function for call to 'MainWindow::connect(QNAMRedirect&, const char*, QTextEdit*&, const char*)'

how can i fix that?

like image 454
Davit Tvildiani Avatar asked Aug 24 '11 18:08

Davit Tvildiani


1 Answers

The reason for the compile error is that the two objects you pass to the connect() function need to be pointers. So using &urlGet (instead of just urlGet) will fix your compile error. However, as soon as your function returns this object will go out of scope and be destroyed, so I suggest you change your function to look something more like this:

QNAMRedirect *urlGet = new QNAMRedirect( this )
QObject::connect(urlGet,SIGNAL(finished(QString)),ui->textEdit,SLOT(setText(QString)));
urlGet->doRequest();

You will, of course, need to take measure that you're not leaking memory here.

like image 143
Chris Avatar answered Oct 19 '22 19:10

Chris