so ive not had too much experience with c++, perhaps only two semesters of college courses which often referenced/used it. ive been trying to learn some Qt, esp after seeing some neat videos of embedded WebKits.
I'm having trouble connecting a signal to a slot in a very simple case. However I suspect this is because I have not declared/defined my classes correctly. I'm posting here because I suspect its my shaky C++ basis rather than the Qt code.
Well here goes:
The following code returns a run time error:
"Object::connect: No such slot QWidget::timeOut()"
I'm trying to connect to MyWidget, not QWidget, but I don't see what is getting mixed up.
Thanks!
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsProxyWidget>
#include <QGraphicsView>
#include <QWebView>
#include <QTimer>
#include <stdio.h>
#include "attempt1.h"
#include <QWidget>
class MyWidget : public QWidget
{
public slots:
void timeOut()
{
printf("hi\n");
update();
}
public:
MyWidget(QWidget *parent = 0)
{
scene = new QGraphicsScene();
setFixedSize(300, 300);
scene->setBackgroundBrush(Qt::yellow);
webview = new QWebView(0);
webProxy = scene->addWidget(webview);
webProxy->scale(.7, .7);
webProxy->shear(0, -.25);
webProxy->rotate(45);
webview->load(QUrl("http://www.google.com/"));
webview->show();
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(timeOut()) );
timer->start();
}
QGraphicsScene* getScene()
{
return scene;
}
private:
QGraphicsScene* scene;
QGraphicsProxyWidget *webProxy;
QWebView *webview;
QTimer *timer;
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MyWidget widget;
QGraphicsView view(widget.getScene());
view.show();
return app.exec();
}
|