Qt is a very easy to use cross-platform application and UI framework, you can define application interface in xml and then interact with this interface using Qt facilities. Qt is the library behind the popular KDE Desktop Enviroment, it allows the developer to create rich desktop interfaces, now Qt has a IDE called Qt Creator, I could create a very simple app that can download some text from internet with few lines of code.
Qt Creator is part of Qt SDK and can be downloaded here.
This is the main window of Qt Creator:
In the image above we are design the main window of an application, we have a widget pallete at the left side of window and object inspector and properties panes at right. You can easy design the application interface by just dragging and drop widgets from pallete to application window in the middle pane of Qt Creator.
Each Qt Creator project contains one or more filestypes below:
Contains the definition of application classes.
Contains the implementation of application classes.
Contains the user interface definition (in xml).
Contains project definition/settings.
As I previously said, I wrote an application that will download some content from internet to show inside application window, in order to do that you must design the application main window exactly like the image above where I used the following widgets: label, line edit, plain text edit and a push button, just drag then from widget pallete to main window exactly like we have above. You also need create 3 files, one that contains application window definition, and the other two with application window code.
This is the header file containing MainWindow class definition:
class MainWindow : public QMainWindow
MainWindow(QWidget *parent = 0);
//Holds an reference to entire ui
//Holds an reference to object that handles http requests
//Declare the method that will handle button click
//Declare the method to be called at http request completion.
#endif // MAINWINDOW_H
And the file below contains MainWindow class implementation:
: QMainWindow(parent), ui(new Ui::MainWindow)
Loading UI definition from mainwindow.ui file,
now the ui variable holds a reference to all components
inside designed window.
This is the event handler for clicks on the button placed
in application main window.
http = new QHttp(this);
Call the showFile method inside this class when
data is successfully downloaded.
connect(http, SIGNAL(done(bool)), this, SLOT(showFile()));
QString texto = ui->txtEndereco->text();
if(texto.length() > 0)
texto = QString("http://%1").arg(texto);
QUrl url = QUrl();
This method will be called when http request is finished
and the data requested is available to application.
QString conteudo = QString(http->readAll());
//Showing the downloaded content into text area.
You can build and run your application by just clicking on Debug->Start Debugging menu.