Development/Tutorials/Qt4 Ruby Tutorial/Chapter 01/fi: Difference between revisions

From KDE TechBase
(Created page with "Tämä rivi lataa QtRuby-laajennoksen.")
(Created page with "'''<tt>app</tt>''' on tämän ohjelman [http://doc.qt.nokia.com/latest/qapplication.html Qt::Application]-ilmentymä. Se luodaan tässä. Välitämme '''<tt>ARGV</tt>''' kohteel...")
Line 58: Line 58:
</syntaxhighlight>
</syntaxhighlight>


'''<tt>app</tt>''' is this program's [http://doc.qt.nokia.com/latest/qapplication.html Qt::Application] instance. It is created here.  
'''<tt>app</tt>''' on tämän ohjelman [http://doc.qt.nokia.com/latest/qapplication.html Qt::Application]-ilmentymä. Se luodaan tässä.  
We pass '''<tt>ARGV</tt>''' to the [http://doc.qt.nokia.com/latest/qapplication.html Qt::Application] constructor
Välitämme '''<tt>ARGV</tt>''' kohteelle [http://doc.qt.nokia.com/latest/qapplication.html Qt::Application]-konstruktori,
so that it can process certain standard command-line arguments (such as '''<tt>-display</tt>''' under X11).  
jotta se voi käsitellä tiettyjä vakiokomentoriviargumentteja (sellaisia kuin '''<tt>-display</tt>''' X11:n alla).  
All command-line arguments recognized by Qt are removed from '''<tt>ARGV</tt>'''.  
Kaikki Qt:n tunnistamat komentoriviargumentit poistetaan kohteesta '''<tt>ARGV</tt>'''.  


<strong>Note:</strong> It is essential that the [http://doc.qt.nokia.com/latest/qapplication.html Qt::Application] object be created before any window-system parts of Qt are used.
<strong>Note:</strong> It is essential that the [http://doc.qt.nokia.com/latest/qapplication.html Qt::Application] object be created before any window-system parts of Qt are used.

Revision as of 18:51, 22 August 2011

Other languages:


Development/Tutorials/Qt4 Ruby Tutorial/Chapter 01


Hei Maailma!
Tutorial Series   Qt4 Ruby-oppikurssi
Previous   Ruby
What's Next   Oppikurssi 2 - Sen kutsuminen saa aikaan lopettamisen
Further Reading   n/a

Hei Maailma!

Tiedostot:

Yleistä

Tämä ensimmäinen ohjelma on yksinkertainen "Hei Maailma"-esimerkki. Se sisältää vain pelkän minimin, jonka tarvitset saadaksesi Qt-sovelluksen toimimaan. Kuva yllä on näytönkaappaus tästä ohjelmasta.

Tässä on sovelluksen täydellinen lähdekoodi:

require 'Qt4'

app = Qt::Application.new(ARGV)

hello = Qt::PushButton.new('Hei Maailma!')
hello.resize(100, 30)
hello.show()

app.exec()

Esittely

Ylimmällä tasolla QtRuby-sovelluksen tavallisesti on suoritettava jonkin kaltainen alustus ja välitettävä ohjaus Qt-kirjastolle, joka sitten kertoo ohjelmalle käyttäjän toimista tapahtumien välityksellä.

Jokaisessa graafisessa käyttöliittymäsovelluksessa, joka käyttää Qt:tä, on tarkalleen vain yksi Qt::Application-objekti. Qt::Application hallinnoi useita sovellustason resursseja, kuten oletuskirjasimia ja kohdistinta.

Qt::PushButton on graafisen käyttöliittymän painonappi, jota käyttäjä voi painaa tai vapauttaa. Se hallinnoi sen omaa käyttötuntumaa, kuten jokainen muu Qt::Widget. Käyttöliittymäkomponentti on käyttöliittymän rajapingaobjekti, joka voi käsitellä käyttäjän syötön ja piirtää grafiikkaa. Ohjelmoija voi vaihtaa sekä käko käyttötuntumaa ja monia sen pienempiä ominaisuuksia (sellaisia kuin väri), samoin kuin käyttöliittymäkomponentin sisältöä. Qt::PushButton voi näyttää joko tekstiä tai Qt::Icon-kuvakkeen.

Läpikäynti rivi riviltä

require 'Qt4'

Tämä rivi lataa QtRuby-laajennoksen.

app = Qt::Application.new(ARGV)

app on tämän ohjelman Qt::Application-ilmentymä. Se luodaan tässä. Välitämme ARGV kohteelle Qt::Application-konstruktori, jotta se voi käsitellä tiettyjä vakiokomentoriviargumentteja (sellaisia kuin -display X11:n alla). Kaikki Qt:n tunnistamat komentoriviargumentit poistetaan kohteesta ARGV.

Note: It is essential that the Qt::Application object be created before any window-system parts of Qt are used.

hello = Qt::PushButton.new('Hello World!')

Here, after the Qt::Application, comes the first window-system code: A push button is created.

The button is set up to display the text "Hello world!". Because we don't specify a parent window (as second argument to the Qt::PushButton constructor), the button will be a window of its own, with its own window frame and title bar.

hello.resize(100, 30)

The button is set up to be 100 pixels wide and 30 pixels high (excluding the window frame, which is provided by the windowing system). We could call Qt::Widget::move() to assign a specific screen position to the widget, but instead we let the windowing system choose a position.

hello.show()

A widget is never visible when you create it. You must call Qt::Widget::show() to make it visible.

app.exec()

This is where our program passes control to Qt. Qt::CoreApplication::exec() will return when the application exits. (Qt::CoreApplication is Qt::Application's base class. It implements Qt::Application's core, non-GUI functionality and can be used when developing non-GUI applications.)

In Qt::CoreApplication::exec(), Qt receives and processes user and system events and passes these on to the appropriate widgets.

You should now try to run this program.

Running the Application

When you run the application, you will see a small window filled with a single button, and on it you can read the famous words: "Hello world!"

Exercises

Try to resize the window. Click the button. If you're running X11, try running the program with the -geometry option (for example, -geometry 100x200+10+20).