簡體   English   中英

沒有匹配的函數c ++

[英]no matching function c++

我正在學習C ++,但遇到了問題。 我正在嘗試制作一個簡單的Web瀏覽器。 可能是因為我在WebWiew中使用了MainWindow類。 如果我在WebWiew中包含MainWindow,則編譯器會說該MainWindow類不存在。

當我將WebView與接口連接時,會出現問題。 我制作了程序的簡短版本。

webview.cpp:6: erreur : no matching function for call to 'WebView::connect(WebView* const, const char*, MainWindow*&, const char*)';

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QtWebKitWidgets>
#include "webview.h"

class MainWindow : public QMainWindow
{
    Q_OBJECT
public:    
    MainWindow();

public slots:
    void adressChanged(QUrl url);
    void setTabTitle(QString title);
    void setProgressionValue(int value);
};

#endif // MAINWINDOW_H

#ifndef WEBVIEW_H
#define WEBVIEW_H

#include <QWebView>

class MainWindow;

class WebView : public QWebView
{
public:
    WebView(MainWindow *interface, QWidget *parent = 0);

private:
    MainWindow *interface;

};

#endif // WEBVIEW_H

#include "webview.h"

WebView::WebView(MainWindow *interface, QWidget *parent) : QWebView(parent), interface(interface)
{
    QObject::connect(this, SIGNAL(titleChanged(QString)), this->interface, SLOT(setTabTitle(QString)));
    QObject::connect(this, SIGNAL(urlChanged(QUrl)), this->interface, SLOT(adressChanged(QUrl)));
    QObject::connect(this, SIGNAL(loadProgress(int)), this->interface, SLOT(setProgressionValue(int)));
}

當您調用QObject::connect()方法時, MainWindow類必須完全合格。 在您的情況下,您只是向前聲明它,因此編譯器不知道MainWindow是從QMainWindow繼承的。 只需將#include "mainwindow.h"添加到webview.cpp

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM