Qt Setup

From WikiSonix
Jump to: navigation, search

Qt is great platform that allows for easy to build GUI applications, and will help make software more portable, as perhaps the future of Ultrasonix platforms lies in multiple platform supports.

Windows Setup[edit]

  • Windows 7 or Windows XP SP3
  • Visual Studio Express 2010
    • Recommended to start for free; as long as no MFC, ATL or .NET bindings are used.
  • Qt (LGPL)
    • Get the Windows libraries compiled under Visual Studio to ensure the proper linker files are packaged. Note the full Windows SDK does not include the proper linker files, but rather MinGW compiled libraries. The full SDK does however include QtCreator, a nice free IDE if you want to go down a VS free route.
    • Version 4.8.1 is released at time of this writing

Visual Studio Setup[edit]

  • Ensure Qt DLL's are in the Windows PATH environment variable (i.e. C:\Qt\4.8.0\bin)
  • Configure a new empty project in Visual Studio
  • Project settings
    • C++
      • Include Qt include directory (i.e. C:\Qt\4.8.0\include)
    • Linker
    • Set the sub-system to Windows, or Console if you want to have a console window floating around with your application
      • Include Qt library directory (i.e. C:\Qt\4.8.0\lib)
      • At minimum you'll want to link to QtGuiX.lib and QtCoreX.lib, where X is the Qt version (4 at the time of writing this).

Simple Example[edit]

If you use the Windows sub-system in your linker settings, the below code will work with no linking errors. If you use the Console sub-system, and are OK with having a console window floating around, just remove the #ifdef block.

#include <QtGui/QtGui>

int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    QWidget window;
    window.resize(320, 240);
    window.show();
    window.setWindowTitle(Application::translate("toplevel", "Top-level widget"));
    return app.exec();
}

#ifdef WIN32
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    return main(__argc, __argv);
}
#endif