User:Declan.mcgrath

    From KDE TechBase
    Revision as of 05:28, 15 August 2009 by Declan.mcgrath (talk | contribs)

    Developing Ruby QT Applications using QT Designer and Ruby on Ubuntu


    These instructions are tested with Ubuntu Jaunty Jackalope 9.04 .


    Install the appropriate packages

    From a command line terminal run

    • sudo aptitude install libkorundum4-ruby1.8
    • sudo aptitude qt4-designer
    • sudo aptitude libqt4-ruby1.8-dev
    • sudo aptitude install libqt4-ruby1.8-examples
    • sudo aptitude install qt4-doc qt4-doc-html  qt4-demos
    • sudo aptitude install qt-creator (you may not need this)


    Create a simple Form with QT4 Designer

    • Create a folder on disk for your project, for example, my_first_project
    • Start up QT4 Designer
    1. Select QT 4 Designer from the Applications->Programming menu or...
    2. From a command line terminal run: designer-qt4
    • The default form is a Dialog with Buttons Right. Stick with that and click Create
    • Drag a List View from the Item Widgets (Item-Based) selection of widgets on the left onto the form. Be careful NOT to choose the List View from the Item Widgets (Model-Based)
    • Right-click the List View that is now dragged on the form
    1. Select Edit Items
    2. Click the green plus icon on the left to add an item
    3. Enter the text: First line
    4. Click the green plus icon on the left to add an item
    5. Enter the text: Second line
    6. Click OK to finish editing items
    • Save what we've done by selecting Save As in the File Menu
    1. Navigate to the folder you created earlier, my_first_project
    2. Choose the filename dashboard.ui for your file and click save
    3. This file contains and XML representation of the form you just created
    • If you want to take a quick look at your form select Preview from the Form menu
    • But we're done with GUI stuff now! Let's get hacking...


    Creating the basic application structure

    • Now that we've got a user interface, we need to run a command (rbuic4) that creates a Ruby class that we can use based on the interface
    • From the command line terminal
    1. Navigate to the my_first_project folder you created earlier using the cd command
    2. Run the command 'rbuic4 dashboard.ui -x -o dashboard_ui.rb'
    3. The '-o dashboard_ui.rb' bit of the command says dump the resulting ruby code into a file called dashboard_ui.rb
    4. The '-x' bit of the command says to create a little stub (like a main function in C/C++ or public static void main in Java) that kicks off the application. Otherwise your application would have no entry point
    5. For instant gratification run the command 'ruby dashboard_ui.rb'
    6. Woaa!!! You should see your beautiful form before you very eyes