Archive for the ‘Uncategorized’ Category

On Qt and Visual Studio

Friday, June 10th, 2011

So your awesome project that you’re developing with Visual Studio, and you want to use Trolltech’s Qt library? Luckily Trolltech provides an awesome Visual Studio plugin that does almost everything Qt creator does (minus Intellisense support for slots). The bad news is that Trolltech doesn’t directly tell you how to go about doing this:

  1. Download and install the Qt for Visual Studio plugin.
  2. Download the source code for Qt 4.7
  3. Start the Visual Studio 2010 Command Prompt ( Microsoft Visual Studio 2010 -> Visual Studio Tools -> Visual Studio Command Prompt)
  4. Navigate to the directory with your downloaded Qt SDK
  5. Run the configure program like so: “configure -platform win32-msvc2010 -debug-and-release -static -no-gif -no-qt3support -no-dbus -no-phonon-backend”
  6. Wait ten or so minutes for configure to finish
  7. Now run nmake. And make dinner, because this will take a very long time
  8. You have Qt ready to go! Yay!

The configure parameters I provide will configure Visual Studio to build the vast majority of Qt. There’s a lot of extra options you can explore if you desire more control – for instance, you can enable exception support.

Have fun!

C++ Template Name Madness

Tuesday, June 22nd, 2010

As I learned today, name lookups with regards to template based inheritance is a nightmare. I’ll try to write more later on why this is the case (two phase lookup), but for know lets highlight the situation.

Pretend you have an awesome templated square matrix class, parameterized on the value type and its size. It would probably look something like this:

// the template class

Once you have the matrix, you’d want to specialize it for specific sizes (say N=4). Its also a good idea to do this so you can add more constructors (doubt you want to keep creating arrays to pass in!). Anyhow, your implementation might end up looking something like

// derieved TMatrix4<T>

Guess what? It won’t work! But before we can get to that, the compiler is going to try to confuse us into thinking the problem is somewhere else! Take the following code. It should work, right?

TMatrix4<float> a = b + c;

Ha! The compiler throws a really nasty error, which I’ll paraphrase here:

“No match for operator= in ‘n=TMatrix<T,N>::operator + ( const TMatrixT,N>& ) const [with T= float, int N=4]“

“What black magic is this?”, I hear you say. Without going into details, the compiler is lying to you – while the compiler is erroring out on the assignment operator it is actually trying to find the constructor. (Return Value Optimization). So, implementing the copy constructor in the derieved TMatrix4 class should solve the problem, right?

Wrong!

// i need to recreate the error for you guys

When you created TMatrix4, you created a templated class that depended TMatrix<T,N>. When you call operator +, it is using TMatrix<T,N>::+ which has a return type of TMatrix<T,N>. Open returning from operator +, it needs to construct a new object – but the compiler cannot tell that the returned object is TMatrix4<T>. So the solution:

TMatrix4( const TMatrix<T,4>& mat )

Don’t panic!

Saturday, October 10th, 2009

I just finished upgrading to the newest WordPress, and guess what! WordPress ate my weblog entries, and its almost 2:00 in the morning. I’ll get everything transferred over tomorrow morning.