Feb 26 2009

Adding Action Listeners in Qt Jambi

Adding an action listener to QT jambi is a little bit different then adding one in regular java. The first and major difference is the absence of an inner class which overrides the actionEvent method inside the action listener class, QT actually accepts string arguments of the method name to call an action listener. So in this case, technically any method can become an action listener. This allows for a greater amount of flexibility and customization when it comes to action listeners in QT.
There are a couple different terms that you need to know about as well when it comes to adding a QT action listener to your code.

Triggered:
When a QAction is created in QT, per say to go into a menu bar to perform something, is clicked… The QSignalEmitter sends off a triggered signal. This is the action listener call you want to keep in mind when taking care of QAction’s from menu bars and toolbars.

Clicked:
This one is pretty straight forward. The clicked keyword is used when a QButton is created. This is to determine if the button was clicked, when the button is clicked, the QSignalEmitter will send a clicked signal.

Connect:
Connect is a keyword used on top of either triggered or clicked. This is used to connect the QSignalEmmiter to the method that will be handling the event as an “action listener”.

The general syntax that is used for a QT Jambi Action Listener is as follows…

1
2
nameOfButton.clicked.connect(locationOfMethod, "methodName()");
nameOfQAction.triggered.connect(locationOfMethod, "methodName()");

The location of the method is this, if the method is in the current class. If it is not specify exactly where it is located so that it can find the method. Then the method name as a string. This will not respond with an error if you type the string in wrong so you will find out at run-time with an error if this has occurred. In this topic i only described both the triggered keyword as well as clickedt. However there are plenty more to choose from. Tutorials on those will come at a later point.

Cheers


Feb 19 2009

School Projects Impairing Creativity

This is an interesting question… Currently we have been given a project in which the back end of the database is provided along with screenshots of all the screens we are allowed to “use”. I find this method extremely limiting to students when it comes to developing abilities “outside the box”. Should students not be allowed to develop their own ideas and thought processes when it comes to programming? Potentially focusing on design and development, and work side by side with technical aspects of the language?

In my opinion concentrating on both design aspects and technical programming concepts will lead to a greater IT work force. How in industry today can you expect perfection in programs from students who are not taught that in school? When they come out then it is left to the employers to teach design, and good technical programming concepts and let’s be honest, they just do not have the time or the resources to do that. So in fact good design principles and practices need to be forced at the school level to ensure a better IT work force when students get into industry and are ready to jump right in!

On a side note, as a proposal, what is there was time set aside during school, for credits, for project work on your own? Google is a great example of this allowing a single day a week for their employees to work on projects of their own or even to go and help the community. And again, they write some of the best code in the world. This is something that could be potentially adopted at the school level to promote creativity and a passion for coding!

Cheers


Feb 17 2009

Creating a Basic Window in Qt

This is a basic piece of code to get you started with the QT Jambi API. Ensure that you have the QT libraries installed before you try and run this code. IF you don’t have this then it won’t run properly and will throw an error. This displays a basic window. Nothing added to it just a basic QT Jambi Window.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import com.trolltech.qt.gui.*;
 
public class basicWindow
{
 private final int WINDOW_WIDTH = 500;
 private final int WINDOW_HEIGHT = 400;
 private QFrame frame;
 
 public basicWindow()
 {
  //create the frame
  frame = new QFrame();
 
  //create the size of the window
  frame.resize(WINDOW_WIDTH, WINDOW_HEIGHT);
 
  //create the layout for the window
  QGridLayout gridLayout = new QGridLayout();
 
  //add the layout to the main frame
  frame.setLayout(gridLayout);
  frame.show(); 
 }
 
 public static void main(String[] args)
 {
  //Used to initialize the window
  QApplication.initialize(args);
 
  //creates a new instance of the basicWindow
  new basicWindow();
 
  //runs the window as an application
  QApplication.exec();
 }
}

Cheers


Feb 17 2009

Swing vs QT Jambi

So I figured I should touch on this as I’ve been frustrated with this for a while at school. First of all I would like to say how frustrating I think java swing is…. I mean you change one thing in the layout and the entire GUI changes for some reason or another that I cannot explain…. So that is my first topic…

Java GridLayout Vs. QGridLayout

QGridLayout is coded in a way that I found extremely easy to use and manipulate. If you change one thing it doesn’t change the rest of the GUI and it keeps everything where you want it to be. You have the ability to set how big you want something to be. Then, based on the size of all the components in your display it displays the GUI in an appropriate manner. Overall the QGridLayout wins this battle.

Java Gui Components Vs. QT Components

The methods that swing uses to handle components causes an extreme amount of code that is not useful when creating a GUI. For instance, when creating a group of radio buttons, you must first create the buttons, then add the buttons to whichever group then add each individual button to a panel or something to make them appear in the GUI. This is crazy in my opinion and there is no reason that you cannot add a ButtonGroup to a panel. In QT you can add whatever component you like to a GUI. This radio button example is just that, one example and there are far too many to display here.

This is just some short thoughts on QT vs Swing, however If you try it out yourself then I’m sure you will find out which is better for yourself. Bye For Now,

Cheers