[SOLVED] Problems with changing text to QWidgets
I can’t figure out why I can’t change the text for my button!
When I try to run my app it just returns: “file:///home/user/Desktop/Bizness/simple_gui/myqml.qml:30:14: Cannot assign to non-existent property “texts” texts: “Right” ^ “
Here is my mypushbutton.h:
- #include <QtDeclarative/QDeclarativeExtensionPlugin>
- #include <QtDeclarative/qdeclarative.h>
- #include <QtGui/QGraphicsProxyWidget>
- #include <QtGui/QPushButton>
- #include <QDebug>
- {
- Q_OBJECT
- public:
- private:
- };
mypushbutton.cpp:
- #include "mypushbutton.h"
- #include <QtGui/QPushButton>
- #include <QDebug>
- {
- setWidget(widget);
- //QObject::connect(widget, SIGNAL(clicked(bool)), this, SIGNAL(clicked(bool)));
- }
- {
- return widget->text();
- }
- {
- if (texts != widget->text()) {
- widget->setText(texts);
- //emit textChanged();
- }
- }
main.cpp
- #include <QApplication>
- #include "piechart.h"
- #include "mypushbutton.h"
- #include <qdeclarative.h>
- #include <QDeclarativeView>
- #include "simple_app.h"
- int main(int argc, char *argv[])
- {
- qmlRegisterType<PieChart>("Charts", 1, 0, "PieChart");
- qmlRegisterType<MyPushButton>("QWidget", 1, 0, "MyPushButton");
- simple_app *dialog = new simple_app;
- dialog->show();
- return app.exec();
- }
and part of my qml
- MyPushButton {
- id: button1
- x: 100; y: 100
- texts: "Right"
- }
However, if I delete this line “texts: “right”“ my app runs fine and shows the QWidget button!
7 replies
xubuntu 11.04 32bit, Qt Creator 2.2.1
And yes I’ve an “import QWidget 1.0” at the top of my QML file
Funny that I’ve successfully implanted this example [doc.qt.nokia.com]
But I can’t get to work with simple button.
Maybe I’ll just install opensuse, because lately the new version of ubuntu has been giving my some headaches. I tried LTS, but I need newer apps than LTS has. And the new 11.04 version has a lot of glitches!
Best Regards
Raivis
Here’s the code I ended up trying (starting with a Creator-generated QML project.)
main.cpp:
- #include <QtGui/QApplication>
- #include "qmlapplicationviewer.h"
- #include "mypushbutton.h"
- #include <qdeclarative.h>
- #include <QDeclarativeView>
- int main(int argc, char *argv[])
- {
- qmlRegisterType<MyPushButton>("QWidget", 1, 0, "MyPushButton");
- QmlApplicationViewer viewer;
- viewer.showExpanded();
- return app.exec();
- }
mypushbutton.h:
- #ifndef MYPUSHBUTTON_H
- #define MYPUSHBUTTON_H
- #include <QtDeclarative/QDeclarativeExtensionPlugin>
- #include <QtDeclarative/qdeclarative.h>
- #include <QtGui/QGraphicsProxyWidget>
- #include <QtGui/QPushButton>
- #include <QDebug>
- {
- Q_OBJECT
- public:
- private:
- };
- #endif // MYPUSHBUTTON_H
mypushbutton.cpp:
- #include "mypushbutton.h"
- {
- setWidget(widget);
- }
- {
- return widget->text();
- }
- {
- if (texts != widget->text()) {
- widget->setText(texts);
- }
- }
main.qml:
- import QtQuick 1.0
- import QWidget 1.0
- Rectangle {
- width: 360
- height: 360
- MyPushButton {
- id: button1
- x: 100; y: 100
- texts: "Right"
- }
- }
You might give it a shot and see if that works for you. If so, it might give you a better starting point for debugging.
Found the problem! A glitch in Qt Creator.
Both of the codes are practically identical!
I just changed the name of function, and suddenly my compiler returns this kind of error:
/home/user/Desktop/Bizness/simple_gui/mypushbutton.cpp:-1: error: undefined reference to `vtable for
Actually 11 of them, all “undefined refernece to ‘vtable ……”
I just deleted all *.o files in my application directory. Rebuilt my project, and everything is OK. That is why the code you gave me worked for me, because I created new project, and so it generated new *.o files!
Thanks!
You must log in to post a reply. Not a member yet? Register here!



