I'm having trouble with making custom slots in Qt. Code:
class.h file:
public slots:
void resetUrl(){
this->load(QUrl("http://www.google.com"));
}
main.cpp file:
#include <QWebView>
#include <QPushButton>
QWebView *web = new QWebView(mainwindow);
QPushButton *button = new QPushButton(mainwindow);
web->load(QUrl("http://www.yahoo.com"));
button->setText("Google");
QObject::connect(button, SIGNAL(clicked()), web, SLOT(resetUrl()));
It gives me a message saying load is not a recognized member. What do I need to change?
Edit: Heres the full webview.h file:
#ifndef WEBVIEW_H
#define WEBVIEW_H
#include <QMainWindow>
#include <QWebView>
namespace Ui {
class webview;
}
class webview : public QMainWindow
{
Q_OBJECT
public:
explicit webview(QWidget *parent = 0);
~webview();
public slots:
void resetUrl(){
this->load(QUrl("http://www.google.com"));
}
private:
Ui::webview *ui;
};
#endif // WEBVIEW_H
You are trying to call a
load()method of yourwebviewclass here:However, your class is derived from
QMainWindow:Both the base class, and your derived class indeed do not have any
load()method. You should derive yourwebviewclass fromQWebViewinstead ofQMainWindow. In this case, the base class'load()method will be called, and it will work fine.