Windows CE QML number oddness
-
I have the strangest of problems, odd integers are increased by one when they are passed from QML scope into a C++ object (through a Q_PROPERTY) for example 89 becomes 90. 90 stays 90, but 101 becomes 102. As you can imagine this is wreaking havoc on my application. All this ONLY on Windows CE...
I've been able to recreate this in a simple application:
MainWindow.h
@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QtGui/QMainWindow>
class MainWindow : public QMainWindow
{
Q_OBJECTprotected:
int m_Id;
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
int id();
Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged )
signals:
void idChanged( int id ) ;
public slots:
void setId( int id );};
#endif // MAINWINDOW_H@
MainWindow.cpp
@
#include "mainwindow.h"
#include <QtDeclarative>
#include <QDebug>MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), m_Id(89)
{QDeclarativeView * view = new QDeclarativeView; setCentralWidget(view); QDeclarativeEngine * engine = view->engine(); engine->rootContext()->setContextProperty("myObject", this); QUrl url = QUrl::fromLocalFile("./test.qml"); view->setSource(url);
}
MainWindow::~MainWindow()
{}
void MainWindow::setId(int id)
{
if (id != m_Id ) {
m_Id = id;
emit idChanged(id);
}
}int MainWindow::id()
{
return m_Id;
}
@test.qml
@import QtQuick 1.0Text {
width: 100
height:100
text: myObject.id
MouseArea{anchors.fill: parent onClicked: { myObject.id = 101 } }
}
@Initially this will display the correct value 89, but once we click on the text the value changes to 102, instead of 101. So the bug appears to be inside the code that transfers values to the C++ objects, not the other way around. Any pointers where to start looking in the Qt code for this would be very very appreciated.
edit: I'm on QT 4.7.3 Windows CE 6
-
For future generations this seems to be a compiler bug
http://bugreports.qt.nokia.com/browse/QTBUG-19792
Fixed by adding floor calls to round64 function in qglobal.h of the corelib.