# Compile QGit with Qt5 and clang¶

## Things that were well documented¶

• Configure Qt5 kit in QtCreator
• first, Compile Qt5 with clang
• in Project, add the Qt5 with clang kit and assign it a different build directory for each target (Debug | Release)
• Fix src/src.pro, by adding:
CONFIG += uic
QT += widgets


(the first is not indicated explicitely in the documentation);
• I tried running qt5/qtbase/bin/fixqt4includes.pl but it didn’t fix anything. I had to add plugins subdirs to #include clauses by hand;
• Comment out all occurences of codecForCStrings() and setCodecForCStrings() (removed in Qt5);
• Replace all Qt::escaped(Qstring& someString) with uses of the someString.toHtmlEscaped() method;
• QHeaderView::setResizeMode() becomes QHeaderView::setSectionResizeMode();

## Things not documented¶

• Replace all QString::toAscii() by QString::toLatin1()
• Replace all (antiquated) uses of QAbstractItemModel::reset() with pairs of QAbstractItemModel::beginResetModel() + QAbstractItemModel::endResetModel() calls;
• QAbstractItemModel::createIndex() has now a subtle overloading (on the third parameter), thus requires an explicit casting;
• qApp->argc and qApp->argv do not exist anymore. All code managing them has to be converted to using the qApp->arguments QStringList (easy but annoying);
• For whatever reason (that I didn’t try to understand completely), in Qt4, the QShortcut::key() call (which returns a QKeySequence can directly be used in a switch construct, as it readily converts to int. Not so in Qt5, so switch constructs using a QShortcut::key() as key have to be converted to cascaded if... else if constructs, which is annoying and error-prone;

## Discrepancies between Qt4 and Qt5 related to compiling QGit¶

If I want a common codebase to compile with both Qt4 and Qt5 in the next few years of transition, I have to use #define clauses to work around the following discrepancies:
• Qt5 puts widgets in QtWidgets directory. This could be solved in the .pro file by explicitely passing a -I\$(QTDIR)/include/QtWidgets directive, or in the source code by providing both versions of the includes in #defines
• Qt4’s Qt::escape is removed in Qt5 and Qt5’s QString::toHtmlEscaped replacement doesn’t exist in Qt4. Will require doubling code;
• Qt4’s QHeaderView::setResizeMode is completely renamed in Qt5 and will require doubling the code
• Finally, the QT += widgets directive in the .pro file raises a warning in Qt4. If I want to be very clean, I’ll need to learn/play some cmake foo.

And that’s all. The other modifications required by Qt5 are compatible with Qt4.