неделя, 2 май 2010 г.

Qt 4.6 on Snow Leopard

Hi folks.

Lately I've been trying to get QT 4.6.2 installed on my Mac. Well that's not that easy as it turned out. Qt 4.6 does have a bug in the installer for Snow Leopard. It just fails in the end. A little googling shows that you need to remove Documentation and Examples from the installation. How the hell you do that? Well, I managed to fix it as follows:

Download the latest installer from the Qt site(mine was 4.6.2). The file is QtSDK.mpkg. Rename the file to QtSDK. Yes, thats a regular directory, so just go inside with Finder. Go in Contents. Open Info.plist. There is a key called "IFPkgFlagPackageList". It contains an array of the subpackages to be installed. Just remove the keys for values Qt_examples and Qt_docs. Save the Info.plist. Go into QtSDK/Contents/Packages and delete Qt_examples.pkg and Qt_docs.pkg (don't know if that's really necessary). Then rename the QtSDK to QtSDK.mpkg again.

There you go. Double click and you should see Installation SUCCESS. Then you can just run again the original installer so you can get the docs and the examples.

сряда, 8 октомври 2008 г.

Java like static blocks in C++

Hi there. I recently moved from java to c++ and I needed a java like static block, but realized that there is no "static { ... }" in c++ so this post is about static blocks in c++, why we need them and how do we write java like static blocks is c++.

Let me have a class like this:


class demo_class {

private: static vector<int> statv;

public: demo_class(int i) {

printf("%d\n", statv[i]);

}

};

/* if you miss this line here, the linker will cry that it can't find a definition for this demo_class::stdev */


vector<int> demo_class::statv = vector<int>(); // line x


And I want this statv vector to be filled with some values before we create an object of this demo_class. The trick here is to define a global static variable of some type and to use its default constructor as a static block. The exercise is even more difficult if the static members are private. But the c++ language has tools for that too. What I need to do is to define this help type, in this case it will be a structure, in demo_class and mark it as "friend" in order to have access of the private static members. Add this `friend struct static_block;` after the constructor. Now I have declared a friend type of our class. I still don't have a definition of this type and I'll do it outside the class definition in а .cpp file just before i create an object from this type static_block. The code goes like this:


static struct static_block {

static_block() {

printf("static_block()\n");

/* you can miss this line here only if you declare _STATIC_BLOCK_INSTANCE after line x. That way you are shure that demo_class::statv will be created and you can use it.*/

demo_class::statv = vector<int>();

for (int i = 0; i <>

demo_class::statv.push_back(i * i);

}

} _STATIC_BLOCK_INSTANCE;


So this is it. The code should work. But remember don't try to use c++ as java ... you will not go any further.

вторник, 23 септември 2008 г.

First one

Hey, folks. This is my first blog. So I have a few ideas in mind to write about. They are just things that took me some time to figure out. Not just coding but any gigs you can do with your computer. My first serious blog coming soon...