Started using QT today for the first time

I started using QT for the first time at work today and I wanted to make a quick sample first to get the feeling. I downloaded the QT SDK qt-win-opensource-4.7.3-vs2008.exe from the QT website and fired VS2008 to write that small snippet that creates a QT window with a embedded browser. It uses WinMain instead of a normal main, so that’s why I pass a dummy argc to QApplication.

This link (in french) is very useful if you want to setup QT for Visual Studio 2010.

 
// Run with PATH=D:\Qt\4.7.3\bin
 
// Windows includes
#include <Windows.h>
#include <tchar.h>
 
// QT includes
#include <QtGui/QtGui>
#include <QtWebKit/QtWebKit>
#include <QtWebKit/QWebView>
 
// QT libs
#pragma comment( lib, "QtCore4" )
#pragma comment( lib, "QtGui4" )
#pragma comment( lib, "QtWebKit4" )
 
// Entry point
int WINAPI _tWinMain(HINSTANCE hInstance, 
                     HINSTANCE hPrevInstance, 
                     LPTSTR lpCmdLine, 
                     int nShowCmd)
{
  QApplication app(nShowCmd, &lpCmdLine);
 
  QWidget window;
  window.resize(1042, 842);
  window.setWindowTitle( QApplication::translate(
    "toplevel", "www.equals-forty-two.com"));
 
  QWebView* view = new QWebView();
  view->load( QUrl("http://www.equals-forty-two.com") );
  view->move(0, 0);
  view->show();
 
  QHBoxLayout *layout = new QHBoxLayout();
  layout->addWidget(view);
 
  window.setLayout( layout );
  window.show();
 
  return app.exec();
}
This entry was posted in C++, Coding, Snippet and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *