Archive
Java, C++: ClassLoader and Qt Resource System
Here a little comparison between the Java ClassLoader and the Qt Resource System:
If you want to load an icon and/or an image e.g. in a Java .jar-file you have to do it this way:
Icon icon;
Image image;
ClassLoader CLDR = this.getClass().getClassLoader();
String path = "src/to/images/name.png";
URL url = CLDR.getResource(path);
// An icon
if (!(url == null)) {
icon = new ImageIcon(url);
}
// An image
try {
image = ImageIO.read(CLDR.getResource(path));
} catch (IOException e) {
// ExceptionHandling here
}
In Qt there is another approach:
The resources associated with an application are specified in a XML-based .qrc-file.
The specified paths are relative to the directory containing the .qrc-file (listed files must be located in the same directory or any sub-directory).
In the source-code the resources are accessible under the same name they have in the source tree, with a “:/” prefix.
Here an example:
<RCC>
<qresource prefix="/dir/subDir" lang="en">
<file alias="AliasName">subDir/FileName<file>
<qresource>
</RCC>
In your source code you can access FileName (if FileName e.g. is a QFile) via
QFile file(":/dir/subdir/AliasName");
after adding the following line to your .pro-file:
RESOURCES = yourRsrcFileName.qrc
The option lang=”langCode” (here: “en”) is for the localization:
If you want to add another language to your application you have to have the file “AliasName_langCode” in your source tree.
And, of course, you don’t have to write the ressource file on your own if you use the QtCreator, there is a nice GUI included.
SICK Robot Day 2009
Today’s the SICK Robot Day 2009 (Link1 | Link2).
I worked on it for the University of Osnabrueck.
Our Robot named KURT avoids collisions, respects the rule “left yields right”, is able to detect numbers as well as markers and drives to the right numbers from 0-9 and/or vice versa.
So…good luck to everyone in Waldkirch.
Here some photos of Kurt2 at our self-made parcours:

And some Videos:
C++: Qt: "qBaseConverter"
Today I implemented a Base Converter in C++ using Qt and after about 15 Minutes first successes have become apparent. You can convert from any Base you want to to any Base you want to (you only have to fix the “Number of Bases”-Variable if the default 30 Bases aren’t enough for you):

The basic Function (Slot) is – guess – “void convert()” that gets a Signal whenever a ComboBox or the Text at the LineEdit gets changed:
bool BaseConverter::getInputNumber(long long &number, int base) {
bool ok;
// Get Input-Number
number = ui->lineEdit_input->text().toULongLong(&ok, base);
// Return if Conversion ok
return ok;
}
void BaseConverter::convert() {
// Base to convert from
int baseFrom = ui->comboBox_choiceFrom->currentIndex() + 2;
// Base to convert to
int baseTo = ui->comboBox_choiceTo->currentIndex() + 2;
long long number;
// If there is a valid Input
if(getInputNumber(number, baseFrom)) {
// Display the converted Number
ui->lineEdit_output->setText(QString::number(number, baseTo));
}
}
