Madsdyd’s Weblog

September 25, 2009

Do not think that you can get fractional seconds into Oracle TIMESTAMP columns from Qt

Filed under: Uncategorized — Tags: — madsdyd @ 10:53 am

Trying to use a QDateTime through a QSqlQuery into Oracle? No fractional seconds turning up?

There is a good reason for this, in the Qt source:

QByteArray qMakeOraDate(const QDateTime& dt)
{
QByteArray ba;
ba.resize(7);
int year = dt.date().year();
ba[0]= (year / 100) + 100; // century
ba[1]= (year % 100) + 100; // year
ba[2]= dt.date().month();
ba[3]= dt.date().day();
ba[4]= dt.time().hour() + 1;
ba[5]= dt.time().minute() + 1;
ba[6]= dt.time().second() + 1;
return ba;
}

Basically Qt treats all QDateTime as DATE, TIME or DATETIME values, and does not transfer the fractional seconds.
So, you have to figure out some other way… as I do as well…

August 19, 2009

Qt does require a QCoreApplication or QApplication object

Filed under: Uncategorized — madsdyd @ 1:32 pm

Just fiddled with an app for 2 hours, trying to get a QTextStream to read stuff in the local encoding. Turns out the app did not have a Q(Core)Application object. Helped a lot to have one such…

June 18, 2009

Encoding for a no-name mp4 player

Filed under: Uncategorized — madsdyd @ 7:51 pm

My kid just got a used AtiPix mp4 player 1GB. It only supports playback of “avi” videos in 320×240. Took a lot of fiddling around, running the windows program in wine, and help from Dark_Shikari in #ffmpeg on irc.freenode.org to figure this ffmpeg command line out:

ffmpeg -i input.mpeg -vcodec libxvid -s 320x240 -b 528000 -aspect 4:3 -r 20 -vtag XVID -acodec mp2 -ab 128000 output.avi

The key would seem to be -vcodec libxvid AND -vtag XVID.

Its a sucky player, but whatever it takes to make the kid happy…

May 26, 2009

KDE 4.2: love/hate & konqueror bugs

Filed under: Uncategorized — Tags: — madsdyd @ 6:03 am

There are tons of great things about kde 4.2 especially for the developers. But there are still lots of features missing, and bugs, some of them glaring. I was hit by one of the more subtle bugs today; konqueror would start with two windows, and then crash. There was no way I could get it running, which was a pain.

Turns out that the file $HOME/.kde/share/apps/konqueror/closeditems_saved was corrupted. Deleting this file fixed everything up.

Now, I really look forward to a new release that fixes the krunner problems and adds dbus functionality to konsole. Then perhaps at some point, an inclusion in ubuntu of the kpilot and a finished akonadi. Then we are about where kde 3.5.9 was when I left it. Especially if I get the apt: io slave back. Sorely missing that one, I am.

March 9, 2009

The magic of C++ templates

Filed under: Uncategorized — Tags: — madsdyd @ 8:57 am

Yesterday I went and wanted to convert a function into a templated function in C++. No big deal, but one of my constructs gave me some problems. I’ll illustrate with an example function, that contains the problem I had

void myfunc( int a ) {
some_class::some_method<some_class>( a );
}

There are good reasons for some_method to be templated with some_class, which has to do with the fact that some_method is static and needs to interface to some C code, that expects static callbacks, and what not.
I wanted to make this work for both some_class, and some_other_class. Here is my first try:

template <class T>
void myfunc( int a ) {
T::some_method<T>( a );
}

This declaration/definition does not work. The compiler wants a primary expression before the first >,and complains about the “,” operator ignoring its first argument.
I was a bit stumped by this, but got some help from ##c++ on irc.freenode.net.
Here is the right way to write it:

template <class T>
void myfunc( int a ) {
T::template some_method<T>( a );
}

Turns out, that when the compiler needs to figure out what some_method is, it can not look in T for help. So, it assumes that some_method is not a templated function, and the first ‘<’ is interprented as operator<. This also explains why it want a primary expression, and why it complains about operator,.

The solution: Let the compiler know that some_method is templated, by inserting “template ” before the method call.

March 7, 2009

Kontact can post to wordpress

Filed under: Uncategorized — madsdyd @ 9:00 pm

Read on userbase.kde.org that kontact can be used to post blog entries, and behold! It works.

March 3, 2009

Exim4 and max size of received messages in kubuntu/debian

Filed under: Uncategorized — Tags: — madsdyd @ 8:24 am

Turns out exim3/4 at some point introduced a max size for messages it wants to receive.

If you have not changed anything, exim will refuse to accept messages larger than 50MB. I need to be able to receive mails larger than this.

Figuring out how to change it under Kubuntu/debian was a bit harder than I thought, but I got some help on irc. First of all, debian allows to configure in two “modes”: split and non-split. This assumes split, which I believe is the default:


sudo echo MESSAGE_SIZE_LIMIT=2000M >> /etc//exim4/conf.d/main/00_exim4-config_localmacrodefs
sudo update-exim4.conf
sudo /etc/init.d/exim4 restart

You can then check that the new size is set with


sudo exim4 -bP message_size_limit

Thanks to valdyn and petemc on irc.freenode.net for helping me out.

October 5, 2008

Boost unit testing strings

Filed under: Uncategorized — Tags: — madsdyd @ 4:28 pm

If you use the boost unit test framework, you probably have a need to test the string output of a function once in a while. If you use BOOST_CHECK_EQUAL Boost kindly reports string differences, by listing the input and output. Then you can start comparing. Not very usefull.

Instead you can use something like this:

boost::test_tools::predicate_result
compare_qstrings( QString const & actual, QString const & expected )
{
// Lets get the trivial case out of the way.
if ( actual == expected ) {
return true;
}
// We want output like this:
// boost_extract_xml_from_es_task_package.cc(106): error in "itemorder":
// check "todo" ==
// output_24575997 failed
// output differs at position 42
// expected ...ISO-8859-1"?>todo
// ^

boost::test_tools::predicate_result res( false );
int i = 0;
int actual_l = actual.size();
int expected_l = expected.size();
int max_l = actual_l < expected_l ? actual_l : expected_l;
if ( actual_l < expected_l ) {
max_l = actual_l;
res.message() << "actual is shorter than expected\n"; // < expected_l ) {
max_l = expected_l;
res.message() << "actual is longer than expected\n"; // << std::endl;
}
while( i < max_l && actual.at( i ) == expected.at( i ) ) {
++i;
}
res.message() << "actual and expected differs at position " << i < 20) ? (i - 20) : 0;
const char * prefix = begin > 0 ? "..." : "";
res.message() << "expected: " << prefix << expected.mid( begin, 70 )
<< ( begin + 70 < expected_l ? "..." : "" ) << "\n"; // std::endl;
res.message() << "actual: " << prefix << actual.mid( begin, 70 )
<< ( begin + 70 < actual_l ? "..." : "" ) << "\n"; // std::endl;
res.message() << " " << QString( ( i - begin ) + QString( prefix ).size(), ' ' ).toStdString()
<< "^"; // << std::endl;
return res;
}

And, call it like this:

BOOST_CHECK( compare_qstrings( "string a", "string b" ) )

and then you will get output like this:


boost_extract_xml_from_es_task_package.cc(470): error in "itemorder": check compare_qstrings( extract.extractXml( input_24229551 ), output_24229551 ) failed. actual is shorter than expected
actual and expected differs at position 23
expected: <ill5:ILL-APDU xmlns:ill5="...
actual: <ill5:ILL-APDU xmlns:ill5="...
^

which is way more useful in my opinion.

Of course, wordpress formats it so it is totally unreadable – so you just have to take my word for it :-)

The above uses QString, but it is of course trivial to change it to use std::string.

August 15, 2008

How to build kdenlive for KDE4 yourself

Filed under: Uncategorized — Tags: , , , — madsdyd @ 7:06 pm

I just updated my wizard that builds Kdenlive for KDE4 on Linux.

It should now be easier than ever (perhaps unless your hobby is tweaking linux video libraries) to get the development version of kdenlive to run on your system.

Get it here – and remember to vote “good” for it :-) .

August 14, 2008

Kinetic Typography

Filed under: Uncategorized — Tags: , — madsdyd @ 4:31 pm

Yesterday, while looking for an answer to a problem with synfig on irv, pixelgeek pointed out Kinetic Typography to me. That is some really cool stuff they do. Be sure to follow the links and watch the videos with sound.

Older Posts »

Blog at WordPress.com.