Mar 16 2009

Creating an Application Specific Console in QT Jambi

I am currently working on a project that required a console with a very specific purpose. It needed to communicate with a custom back-end protocol for use in a client/server environment. This sort of specific tutorial is not surprisingly unavailable online. The first step when setting up an application specific console is actually setting up the back-end. This is something that will be potentially done as a future tutorial. Anyways back to building the console window. The components included in the console window will be one QTextEdit, and one QLineEdit. This can be constructed in any way you like. The QTextEdit can be on the bottom and the QLineEdit on top or the other way around, that’s up to you.

Next, we will need to be adding a custom action listener to the QLineEdit so that when the enter key is pressed inside the QLineEdit the command will be sent to the server and then displayed in the QTextEdit window. As a future feature implementation, syntax highlighting could be implemented for an easier display inside the QTextEdit window. The custom action listener to add to the QLineEdit bar looks like this…

1
QLineEdit.returnPressed.connect(this, "NameOfActionListenerMethod()");

This will ensure that everytime the enter button is pressed, the string that the user entered will be able to be transfered to the server, or wherever else in the program you would like it to go. Now for the action listener method. The method should be declared as public with a return type of void.

1
2
3
4
5
public void terminalWindowEnterPressed()
    {
        terminalWindow.append(enterArea.text());
        enterArea.setText("Protocol Name > ");
    }

Then once you have the action listener built to just send the data to the window, you can do the same with sending it across a network.

All Together the code looks like this. All you have to do is copy/paste the code into your program and use it at will.

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
/**
     *
     */
    public void buildTerminal()
    {
        terminalFrame = new QFrame();
        terminalFrame.setWindowTitle("Window Title");
 
        terminalWindow = new QTextEdit();
        terminalWindow.setReadOnly(true);
 
        enterArea = new QLineEdit();
        enterArea.setText("Protocol Name > ");
        enterLabel = new QLabel("Enter Command");
 
        terminalFrame.setMinimumSize(600, 400);
 
        enterArea.returnPressed.connect(this, "terminalWindowEnterPressed()");
 
        QGridLayout layout = new QGridLayout();
        layout.addWidget(terminalWindow,0,0,10,10);
        layout.addWidget(enterArea,11,1,1,9);
        layout.addWidget(enterLabel, 11,0,1,1);
 
        terminalFrame.setLayout(layout);
        terminalFrame.show();
    }
 
    /**
     *
     */
    public void terminalWindowEnterPressed()
    {
        terminalWindow.append(enterArea.text());
        enterArea.setText("Protocol Name > ");
    }

Cheers


Mar 5 2009

Optional Courses at School

At our school, the way they have the course schedule set up, all of your courses are pre-selected for you. This leaves no room for specialization and leads to a degree that is similar to the person’s beside you. Where does this put you in the eye’s of the employer coming out of the program? With the exception of marks and maybe the odd bit of experience if you’re outgoing enough, it puts you on the same level. In a potentially collapsing economy, diversity is key. If you can diversify the courses offered, students will be better prepared for industry.

Students adaptability is the key to their survival, when they get out of school. I heard a statistic once, that said 80% of the students graduating will not be coding in the same language(s) that they took in school. If students have the ability to specialize, even with a few courses, it could lead to more prepared graduates.

Things like game design and graphics could have the ability to be taught as early on as second year. If students are given the choice to take these types of courses, then the interest would spark an increased learning potential for the students, as opposed to sticking them in classes that are “required”. This of course is from a students point of view, but I think employers would see the significance in this method of action as well.

Cheers


Mar 1 2009

Program Design

So in school, we are learning some fundamentals on object oriented design in Java such as inheritance and polymorphism. The thing that we haven’t done is the actual concept of object oriented design. So things like how to structure classes and methods for optimal code efficiency and use. This is such a fundamental concept to teach in school to allow programmers just coming out of school to produce optimized and efficient code.

It’s no matter in today’s society we deal with so many programs that crash and don’t work properly. If fundamental programming techniques such as design are not being taught, then when students graduate it is to be expected that they continue the programming practices that they picked up in college/university.

This being said, when you come out of college/university, you’re most likely to have a “code monkey” position, where you’re actually coding the enterprise applications. So it’s almost expected, knowing this that programs you use everyday crash on such a regular basis.

Cheers