Showing posts with label qt. Show all posts
Showing posts with label qt. Show all posts

Friday, December 30, 2011

Access QML Element properties from C++

Qt provides various method for working with QML. This following tutorial shows, how a QML Element properties can be accessed and modified from C++ code using QDeclarativeProperty class.

It will show a simple idea on accessing properties which cannot be accessed directly.

main.qml

import QtQuick 1.1

Rectangle {
    id: parentRect
    property bool layoutValue : LayoutMirroring.enabled ? true : false;// Read Only
    LayoutMirroring.enabled: false
    LayoutMirroring.childrenInherit: true
    width: 300; height: 50
    color: "yellow"
    border.width: 1

    Row {
        anchors { left: parent.left; margins: 5 }
        y: 5; spacing: 5

        Repeater {
            model: 5

            Rectangle {
                color: "red"
                opacity: (5 - index) / 5
                width: 40; height: 40

                Text {
                    text: index + 1
                    anchors.centerIn: parent
                }
            }
        }
    }
}


main.cpp

#include 
#include 
#include 
#include 
#include "qmlapplicationviewer.h"

Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QScopedPointer app(createApplication(argc, argv));
    QScopedPointer viewer(QmlApplicationViewer::create());

    viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer->setMainQmlFile(QLatin1String("qml/Test/main.qml"));
    QDeclarativeProperty propLayout(viewer->rootObject(),"layoutValue");
    QDeclarativeProperty propLayoutMargin(viewer->rootObject(),"anchors.leftMargin");

    qDebug() << "Layout Property :" << propLayout.read().toBool();
    qDebug() << "Layout Margin :" << propLayoutMargin.read().toReal();

    qDebug() << "Property Modified? " << propLayoutMargin.write(QVariant::fromValue(20));
    if(propLayout.type() == QDeclarativeProperty::Invalid)
        qDebug() << "Invalid Layout Mirror property";
    if(propLayoutMargin.type() == QDeclarativeProperty::Invalid)
        qDebug() << "Invalid Anchor Margin property";
    viewer->showExpanded();

    return app->exec();
} 

Wednesday, December 14, 2011

Qt for Android - __atomic_inc undefined error!

I have also encountered this error. This is how I rectified.

Select Projects on the left panel (below Debug). Select "Build" in the top and make sure the Qt Version and arm configuration are same in
1) Compilation Target (Android robot symbol)
2) Edit Build Configuration (drop down list box)
3) Qt Version (General category)

Now click "Run" next to "Build". Now select atleast "android-8" as the Android target. Now clean the project and click rebuild. This should clear this error.

Wednesday, September 21, 2011

Install Qt MYSQL Driver for Linux (Ubuntu).

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QSQLITE2

You might have come across this error, if you are using Qt SDK from Nokia.

Now follow these steps to get MYSQL working with Qt Creator.

Go to System-> Administration-> Synaptic manager and search "libqt4-sql-mysql" (libqt3-sql-mysql if you are using Qt3) and install the library by right clicking and select Mark for installation.



Now, in your Qt code add this line
                                qDebug() << QCoreApplication::libraryPaths();

You will see something like this upon running your program.
("/home/raja/QtSDK/Desktop/Qt/473/gcc/plugins", "/home/raja/Documents/QtProjects/SyncTest-build-desktop")

Now copy libqsqlmysql.so (search it or find it as shown in the above picture) to the above path. You can also use the library by using QCoreApplication::addLibraryPath(QString path).

Monday, September 19, 2011

Some random things about Qt & QML!

Someone asked a question in stack overflow about the future of Qt and Qt's future support for Desktop. A thought of sharing you what my answer was to him.



The future of Qt is never uncertain. The one who said, "there is not interest in desktop" is not the owner. The future of Qt is well mentioned after the Feb'11 (announcement of WP7 collaboration). In fact, QML is Good way to go for future UIs.

For your proof, the new Unity Interface for Ubuntu is going to have a 2D QML interface and the future editions are going to have QML 3D interface for some applications. The new Ubuntu is highly integrated with Qt.

The way Qt is going is too good so far. As a regular reader of Qt blogs and labs, I can say it for sure. The new Qt 5 is going to have lot of features and performance improvements. Also, they have committed its development to the successful Open Governance model. So, everyone can contribute.

Since the future of development is going to be for Mobiles and Tablets, most of the tutorials you will find may seem to create an illusion that Qt has no support for Desktop, but its not the case.

Download the latest Qt SDK 1.3 and you will find the Qt 4.7.4 for Desktop.

To ease the use of Qt, for developing both mobile and desktop applications, Nokia has combined both development environment into one SDK called Qt SDK, unlike the previous Nokia Qt SDK.

Moreover, I think no other C++ development framework can support a wide range of platforms like Qt supports now.

I supports: -
  • Desktop OSs: Windows, Linux, Mac OSx. 
  • Mobiles OSs: Symbian, Android (Community cupported), IOS (Comunity supported), Windows CE, Embedded Linux devices, Meego, Maemo. 
  • Tablet OSs: Android, Meego, Tablet Linux ports.

A new opportunity for porting it to is available in the name of Qt Necessitas- The Android port and IOS port of Qt are based on this only. If you have doubts check the YouTube for videos.

And regarding Java, I have read it is not that cross platform as Qt is. I also doubt whether any IDE, other than Qt can give you the comfort of cross compiling.
The Documentation is too good that, for rare cases where cross platform is not supported (for some Window functions) is mentioned explicitly along with alternative methods to implement it in that particular OS.

QML is awesome, since its behind the scene actions are performed using C++ to give you similar performance (85% as fast as Qt C++). And you don't have the head ache of Memory Management (if you are not used to with C++). If you really want a beautiful GUI and fast performance go for QML and C++.. Else the easy option is to use QML and Javascript.
I'm developing an application for Symbian, using heavy animations in my Nokia E63 with a CPU clock speed of 386 MHz and QML performance is smoother and doesn't hangs at all.

You can even find the OS and version with an if else statement, that easy. Give it a try before deciding it by reading some reviews.




Wednesday, July 27, 2011

My Second ever QML program! (A simple QML Program)

Since I have done my  final year project in Qt for Symbian, I have become a fan of Qt and QML. So I just wanted to try something in QML rather than Hello World! I always wanted to have a good Stop Watch in my mobile, so I just went straight away to right it in QML.

It merely took around 12 hours for me to code this decent looking looking app, but I have written it immediately after my Hello World in QML. So after getting used to it, it won't be time consuming.

I have published the app to OVI store, but I don't have the patience for it to get approved in the QA process, so I'm linking the packages here for you to try. The name says it all, download appropriate packages for your Symbian phone and Maemo.

Note : Before that you have to install the necessary Qt packages, and it must be of the version Qt 4.7.0 or higher. Qt Mobility packages are not necessary.

If you don't know what Qt and Qt Mobility packages are, then install the following package in your device.

If you are already using Qt or QML apps on your device, then start downloading the appropriate package for your mobile phone.

Update: 

To download SIS file!

This is the self signed package for all devices like S60 V3 FP1, FP2, S60 V5, Symbian^3.

stopwatch_qt-4_7_0_m1_0_2_maemo5.deb - 331.3 KB
This is the Maemo 5 compatible Debian package. This package is not tested in real device.

For shortcuts: RR-StopWatch
Your Ad Here