Qt’s Phonon library has an awesome goal: abstract video and audio services to simplify cross-platform development. It has worked great for me out of the box using Qt 4.7 on linux and Mac OS X. Windows setup took a bit of elbow grease. Here are the cheatnotes to get you through it quickly.

NOTE: The Qt mingw setup worked fine for me when I was setting up my first Windows development environment, do not hesitate to go that route. All you need is the Qt SDK for Windows. Free is good!

But this time around, I opted for using Visual Studio 2010, since I already had it installed and I wanted to compare. I’ve read that there is no support for using the open-source-licensed Qt with Visual Studio, but the official Qt download page for the Visual Studio Add-In clears things up – it says the add-in “can be used for development together with all Qt licenses”. Let’s fire it up and try it out! (continued…)

Here is my published reusable c++ code, which includes a version of a sorted vector that I’ve been using for years. It may not be academically sterile C++, I’m more interested in getting things done, and I had to crank out some new functionality needed for my upcoming media manager. But it should be solid production code. It glues together std::vector with std::sort, std::lower_bound, etc., which is a pretty fscking logical thing to do – who wants to redo that every time you have data to manage? :> My favorite part is the find_it_or_fail() function, the only real extension of functionality. Basically, it extends lower_bound() in a logical way, so you either get a hit, or failure (indicated by returning vector::end()). There are also versions of member functions with predicate function parameters, to help you use it with vectors of object pointers, which isn’t exactly straightforward in C++. Let me know if it seems useful or sucky. :>

Reusable STLContainers code
old wiki copy of sorted_vector

Just a quick note: I feel like I’ve accomplished a lot today just because I READ this article. Nice bomb drop. We’ll see what I do with it… I think it’s a bit too crunchy to put into use – I don’t feel like dealing with any gotchas on all the versions of all the compilers I’m using, as there are a LOT these days. But it has lead me to research other progress in the C++ standard. The boost function library, which has been accepted into TR1, is already available in some compiler spaces, whoop.

I started down this path because I wanted to store a predicate function in my sorted_vector class. For now I can get by without this stuff, always passing in a functor to the function calls that need it, but that’s not as elegant.

Meanwhile, it’s upwards and onwards with QT slots and signals – QT is getting the job done for me in a major way. There are boost::signal and boost::bind as alternatives to that, but I’m really kicking out the jams with QT, so I’m not stopping now. More to come soon, hopefully.

UPDATE: C++0x is hopefully coming soon. Wikipedia, as usual, gives a nice overview and some nice guidance. In particular, I need to avoid std::auto_ptr and function object base classes (std::unary_function, std::binary_function) which are slated for removal(!). Sounds like I need to keep my eye out for polymorphic wrappers for function objects, they may be just the ticket I need. Check out the whole standard, it’s juicy! :>

UPDATE 2: Here is a nice rundown of options for the sort predicate function, leading into the C++0x solution.

Recently, I found myself kind of annoyed by the fact that I couldn’t use the same “initialization” syntax to directly set the values of an existing structure. Extremely trivial, but it bugs me. Is there really a good reason for this limitation?

	typedef struct
	{
	    int x;
	    int y;

	} Doh;

    Doh doh = { 1, 2 };

    // You can't directly re-assign in one step, bummer.
    // doh = { 3, 4 };

    // You need a second struct to use the same syntax.  Yuck.
    Doh d2 = { 3, 4 };   
    doh = d2;

    // Or just do it longhand.  Also yuck.
    doh.x = 5;
    doh.y = 6;

So I dug around to see if there was anything I was missing, and I found designated initializers, the new initialization method available in C99. It doesn’t allow me to directly assign values to an existing structure, but it is interesting:

	Doh doh_set = { 
	    .x = 4,
	    .y = 3
	};
	Doh doh_set2 = { 
	    .y = 3, 
	    .x = 4 
	};
	Doh doh_set3 = { 
	    .y = 3
	};
    Doh set4[]=
    {
        {
            .y  = 1039      
        },
        {
            .y  = 1040,
            .x  = 23
        }
    };

Still not rocket science, but the truly interesting part is that designated initializers are not yet available in C++. At least not today. I tested it with gcc 4.1.2 and Visual Studio 2008 C++ compilers and they do not support it. It may appear in C++0x, but for now, C is definitely no longer a pure subset of C++. For more possible gotchas (and some C99 features that make it more compatible with C++), here’s a quick C99 rundown.

Considering designated initializers are being used in places like the linux kernel, this issue no longer seems trivial. Oh well, code and learn. Hopefully I can go another 10 years(!) before my next snag. For now, back to classes… :>