Friday, October 30, 2015

Hello World Qt, hand made from Empty qmake Project

This video show how to create Empty qmake Project in Qt Creator, create .cpp and edit .pro to make a Hello World application.


main.cpp

#include <QApplication>
#include <QPushButton>

int main(int argc, char *argv[]){
    QApplication app(argc, argv);
    QPushButton qPushButton("Hello Qt");
    qPushButton.show();
    return app.exec();
}


You will be reported with error of:
QApplication: No such file or directory
QPushButton: No such file or directory

To fix it: Edit HelloQt.pro to add the code QT+=widgets.
QT+=widgets
SOURCES += \
    main.cpp


libGL error: core dri or dri2 extension not found and failed to load driver: vboxvideo

In case you install QtCreator on Ubuntu under VirtualBox, and QtCreator cannot run caused by:
libGL error: core dri or dri2 extension not found
libGL error: failed to load driver: vboxvideo

Try to close Ubuntu, disable 3D Acceleration of Setting > Display in VirtualBox, and restart Ubuntu again.


Wednesday, October 28, 2015

Chage Qt5 Example of Calendar to set today

The Qt Creator Examples: Qt5 Calendar preset date to 2014 January 1. By default, the date of Calendar is today.

To change the data of Qt Calendar Example, edit qml/main.qml, simple comment the code selectedDate: new Date(2014, 0, 1)




Monday, October 26, 2015

Qt Creator Examples - Qt Quick Controls Gallery


This example project demonstrates the various UI components provided by Qt Quick Controls.

error: qtquickcontrolsapplication.h: No such file or directory

If you try to build Qt Creator Examples and reported error of qtquickcontrolsapplication.h: No such file or directory.

Most probably you install Qt with sudo, the default install location is /opt, a user un-writable location. When you build Qt Creator Examples, you have to copy the project to another user writable location, it break the links and lost the shared directory.

May be you have to un-install Qt. Re-install to another user writable location, or re-install WITHOUT sudo (the default location is your HOME). Such that you need not copy the project when create examples.



How to uninstall Qt

To unstall Qt:

open terminal, go to the installed directory, run MaintenanceTools:

$ ./MaintenanceTool


Qt Creator Examples: Qt5 Calendar


The Calendar example displays a Calendar control and an events list for the selected date. It uses a C++ class to fetch the event details from an SQLite database. The example app uses a custom CalendarStyle to highlight the selected date and mark the dates that have events.


To set date to today: Chage Qt5 Example of Calendar to set today