The following code compiles properly but shows NOTHING on QML window.
.cpp
#include "q.h"
Lcdnumber
:: Lcdnumber(QGraphicsItem *parent
) : QGraphicsProxyWidget
(parent
){
number->display(11);
}
int main (int argc, char *argv[])
{
qmlRegisterType <Lcdnumber> ("Q", 1, 0, "Lcdnumber");
QDeclarativeView view;
view.
setSource (QUrl :: fromLocalFile ("qq.qml"));
view.show ();
return app.exec();
}
#include "q.h"
Lcdnumber :: Lcdnumber(QGraphicsItem *parent) : QGraphicsProxyWidget(parent)
{
number = new QLCDNumber();
number->display(11);
}
int main (int argc, char *argv[])
{
QApplication app (argc, argv);
qmlRegisterType <Lcdnumber> ("Q", 1, 0, "Lcdnumber");
QDeclarativeView view;
view.setSource (QUrl :: fromLocalFile ("qq.qml"));
view.show ();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
.h
#ifndef LCDNUMBER_H
#define LCDNUMBER_H
#include <QtDeclarative/QDeclarativeExtensionPlugin>
#include <QtDeclarative/qdeclarative.h>
#include <QGraphicsProxyWidget>
#include <QDebug>
#include <qdeclarative.h>
#include <QDeclarativeView>
#include <QApplication>
#include <QWidget>
#include <QLCDNumber>
class Lcdnumber : public QGraphicsProxyWidget
{
Q_OBJECT
public:
~Lcdnumber() {}
private:
};
#endif // LCDNUMBER_H
#ifndef LCDNUMBER_H
#define LCDNUMBER_H
#include <QtDeclarative/QDeclarativeExtensionPlugin>
#include <QtDeclarative/qdeclarative.h>
#include <QGraphicsProxyWidget>
#include <QDebug>
#include <qdeclarative.h>
#include <QDeclarativeView>
#include <QApplication>
#include <QWidget>
#include <QLCDNumber>
class Lcdnumber : public QGraphicsProxyWidget
{
Q_OBJECT
public:
Lcdnumber(QGraphicsItem *parent = 0);
~Lcdnumber() {}
private:
QLCDNumber* number;
};
#endif // LCDNUMBER_H
To copy to clipboard, switch view to plain text mode
qml
import QtQuick 1.0
import Q 1.0
Rectangle
{
id: window
Lcdnumber
{
id: button1
anchors.centerIn: parent
width: 600; height: 600
}
}
import QtQuick 1.0
import Q 1.0
Rectangle
{
id: window
Lcdnumber
{
id: button1
anchors.centerIn: parent
width: 600; height: 600
}
}
To copy to clipboard, switch view to plain text mode
SOLVED
I forgot to add:
setWidget (number);
setWidget (number);
To copy to clipboard, switch view to plain text mode
in constructor.
Bookmarks