Qt: различия между версиями

Содержимое удалено Содержимое добавлено
Установка QT, первая QT программа
Строка 7:
 
см [[Qt ЧАВО]]
 
== Установка Qt 4.2.2. из исходных кодов под «Visual C++ 2005 Express Edition» ==
* Скачайте и установите «[http://msdn.microsoft.com/vstudio/express/downloads/ Visual C++ 2005 Express Edition]»
* Скачайте и установите «[http://msdn.microsoft.com/vstudio/express/visualc/usingpsdk/ MS Platform SDK]»
Достаточно будет установить «Microsoft Windows Core SDK». Если вам понадобиться доставить, какой-нибудь другой SDK, вы сможете это сделать в «Установка и удаление программ» "Панели управления».
* Настройка «Visual C++ 2005 Express Edition» под «MS Platform SDK».
 
По этой [http://msdn.microsoft.com/vstudio/express/visualc/usingpsdk/ ссылке] написано на английском языке.
 
** Обновите Visual C++ дериктории в разделе Projects and Solutions диалогового окна Options.
Добавьте пути в следующих секциях:
*** Executable files: C:\Program Files\Microsoft Platform SDK\Bin;
*** Include files: C:\Program Files\Microsoft Platform SDK\include;
*** Library files: C:\Program Files\Microsoft Platform SDK\lib.
 
Замечание: Обновить директории можно другим способом, для этого нужно изменить файл VCProjectEngine.dll.express.config размещенный в \vc\vcpackages. Убедитесь что вы удалили файл "vccomponents.dat" размещенный в "%USERPROFILE%\Local Settings\Application Data\Microsoft\VCExpress\8.0" перед перезапуском Visual C++ Express Edition.
 
** Обновите файл corewin_express.vsprops.
 
Этот шаг нужен для того чтобы сделать в Visual C++ Express шаблон приложений Win32. Измените файл corewin_express.vsprops (размещенный в C:\Program Files\Microsoft Visual Studio 8\VC\VCProjectDefaults) в следующих местах:
 
AdditionalDependencies="kernel32.lib"
 
замените на
 
AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib"
 
* Настройка «Visual C++ 2005 Express Edition» под Qt 4.2.2.
** Измените файл vsvars32.bat (если вы установили Visual C++ 2005 Express Edition в папку C:\Program Files\Microsoft Visual Studio 8\, то файл должен находиться в папке C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\) в следующих местах:
 
@set INCLUDE=C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE;%INCLUDE%
замените на
@set INCLUDE=C:\Program Files\Microsoft Platform SDK\Include;C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE;%INCLUDE%
и
@set LIB=C:\Program Files\Microsoft Visual Studio 8\VC\LIB;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\lib;%LIB%
замените на
@set LIB=C:\Program Files\Microsoft Platform SDK\Lib;C:\Program Files\Microsoft Visual Studio 8\VC\LIB;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\lib;%LIB%
* Скачайте [http://www.trolltech.com/developer/downloads/qt/windows Qt 4.2.2./Windows Open Source Edition] и разархивируйте его в любую свободную папку (далее будем считать, что эта папка C:\qt-win\).
* Скачайте [http://prdownloads.sourceforge.net/qtwin/ патч для Qt 4.2.2] и разархивируете его в папку C:\qt-win\.
* Сборка (конфигурирование, компиляция и линковка)
** Запустите "MS Visual C++ 2005 Express Edition".
** Выберите пункт меню Tools->Visual Studio 2005 Command Prompt.
** Наберите в командной строке
cd c:\qt-win
чтобы перейти в каталог с исходными текстами.
** Наберите в командной строке
installpath42.bat
чтобы пропатчить исходные тексты.
** Наберите в командной строке
qconfigure msvc2005
чтобы произвести конфигурирование. На все запросы нажимайте 'y'.
** После успешного конфигурирования, система попросит набрать nmake, так и сделайте и идите пить чай, кофе, сок, пиво... Процесс очень долгий.
 
Замечание: конфигурирование для MS Visual C++ 2005 Express Edition сервис пак 1 может не пройти, нужно подправить исходный текст: в файле C:\qt\src\corelib\tools\qmap.h кусок кода:
 
template <class Key, class T>
class QMultiMap : public QMap<Key, T>
{
public:
QMultiMap() {}
QMultiMap(const QMap<Key, T> &other) : QMap<Key, T>(other) {}
inline typename QMap<Key, T>::iterator replace(const Key &key, const T &value);
inline typename QMap<Key, T>::iterator insert(const Key &key, const T &value);
inline QMultiMap &operator+=(const QMultiMap &other)
{ unite(other); return *this; }
inline QMultiMap operator+(const QMultiMap &other) const
{ QMultiMap result = *this; result += other; return result; }
private:
T &operator[](const Key &key);
const T operator[](const Key &key) const;
};
template <class Key, class T>
Q_INLINE_TEMPLATE Q_TYPENAME QMap<Key, T>::iterator QMultiMap<Key, T>::replace(const Key &akey, const T &avalue)
{ return QMap<Key, T>::insert(akey, avalue); }
template <class Key, class T>
Q_INLINE_TEMPLATE Q_TYPENAME QMap<Key, T>::iterator QMultiMap<Key, T>::insert(const Key &akey, const T &avalue)
{ return QMap<Key, T>::insertMulti(akey, avalue); }
заменить на
 
template <class Key, class T>
class QMultiMap : public QMap<Key, T>
{
public:
QMultiMap() {}
QMultiMap(const QMap<Key, T> &other) : QMap<Key, T>(other) {}
inline typename QMap<Key, T>::iterator replace(const Key &akey, const T &avalue)
{ return QMap<Key, T>::insert(akey, avalue); }
inline typename QMap<Key, T>::iterator insert(const Key &akey, const T &avalue)
{ return QMap<Key, T>::insertMulti(akey, avalue); }
inline QMultiMap &operator+=(const QMultiMap &other)
{ unite(other); return *this; }
inline QMultiMap operator+(const QMultiMap &other) const
{ QMultiMap result = *this; result += other; return result; }
private:
T &operator[](const Key &key);
const T operator[](const Key &key) const;
};
//template <class Key, class T>
//Q_INLINE_TEMPLATE Q_TYPENAME QMap<Key, T>::iterator QMultiMap<Key, T>::replace(const Key &akey, const T &avalue)
//{ return QMap<Key, T>::insert(akey, avalue); }
//
//template <class Key, class T>
//Q_INLINE_TEMPLATE Q_TYPENAME QMap<Key, T>::iterator QMultiMap<Key, T>::insert(const Key &akey, const T &avalue)
//{ return QMap<Key, T>::insertMulti(akey, avalue); }
 
и в файле C:\qt\src\corelib\tools\qhash.h кусок кода:
 
template <class Key, class T>
class QMultiHash : public QHash<Key, T>
{
public:
QMultiHash() {}
QMultiHash(const QHash<Key, T> &other) : QHash<Key, T>(other) {}
inline typename QHash<Key, T>::iterator replace(const Key &key, const T &value);
inline typename QHash<Key, T>::iterator insert(const Key &key, const T &value);
inline QMultiHash &operator+=(const QMultiHash &other)
{ unite(other); return *this; }
inline QMultiHash operator+(const QMultiHash &other) const
{ QMultiHash result = *this; result += other; return result; }
private:
T &operator[](const Key &key);
const T operator[](const Key &key) const;
};
template <class Key, class T>
Q_INLINE_TEMPLATE Q_TYPENAME QHash<Key, T>::iterator QMultiHash<Key, T>::replace(const Key &akey, const T &avalue)
{ return QHash<Key, T>::insert(akey, avalue); }
template <class Key, class T>
Q_INLINE_TEMPLATE Q_TYPENAME QHash<Key, T>::iterator QMultiHash<Key, T>::insert(const Key &akey, const T &avalue)
{ return QHash<Key, T>::insertMulti(akey, avalue); }
 
заменить на
template <class Key, class T>
class QMultiHash : public QHash<Key, T>
{
public:
QMultiHash() {}
QMultiHash(const QHash<Key, T> &other) : QHash<Key, T>(other) {}
inline typename QHash<Key, T>::iterator replace(const Key &akey, const T &avalue)
{ return QHash<Key, T>::insert(akey, avalue); }
inline typename QHash<Key, T>::iterator insert(const Key &akey, const T &avalue)
{ return QHash<Key, T>::insertMulti(akey, avalue); }
inline QMultiHash &operator+=(const QMultiHash &other)
{ unite(other); return *this; }
inline QMultiHash operator+(const QMultiHash &other) const
{ QMultiHash result = *this; result += other; return result; }
private:
T &operator[](const Key &key);
const T operator[](const Key &key) const;
};
//template <class Key, class T>
//Q_INLINE_TEMPLATE Q_TYPENAME QHash<Key, T>::iterator QMultiHash<Key, T>::replace(const Key &akey, const T &avalue)
//{ return QHash<Key, T>::insert(akey, avalue); }
//
//template <class Key, class T>
//Q_INLINE_TEMPLATE Q_TYPENAME QHash<Key, T>::iterator QMultiHash<Key, T>::insert(const Key &akey, const T &avalue)
//{ return QHash<Key, T>::insertMulti(akey, avalue); }
* Настройка переменных окружения.
** Мой компьютер -> Свойства, вкладка дополнительно, кнопка Переменные среды.
*** Установите переменную окружения QTDIR в c:\qt-win.
*** Установите переменную окружения QMAKESPEC win32-msvc2005.
*** Добавляем к переменной окружения PATH путь %QTDIR%\bin.
 
== Hello world ==
 
* Создайте папку helloworld;
* Создайте файл helloworld.cpp
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello Qt!");
label->show();
return app.exec();
}
* Запустите "MS Visual C++ 2005 Express Edition".
* Выберите пункт меню Tools->Visual Studio 2005 Command Prompt.
* Из консоли перейдите в вами созданную папку helloworld.
* В консоли наберете:
qmake -project
qmake -tp vc helloworld.pro
* Откройте созданный файл helloworld.vcproj.
* В среде Visual Studio выберите пункт меню Debug -> Start Debugging.