PDA

View Full Version : How to install and run old Qt4?



Maluko_Da_Tola
29th October 2013, 12:01
Hi everyone,

I created an application a good while ago in Qt4. Recentrly I installed Qt5 and it won't run, displaying an error: error: QDialog: No such file or directory #include <QDialog>

I did some google search and added 'QT += widgets' to the .pro file. Well this error was gone but 281 new errors featuring incompatilities with QLabels, etc appeared.

I then decided to jump out of Qt 5 and go back to Qt4. This is where trouble starts: I installed the Qt4 libraries from http://qt-project.org/downloads but I cannot find a way of running actual Qt4 or, alternatively, running Qt5 using the Qt4 libraries.

Any suggestions on how to get Qt4 to run on windows 7?

Thank you.
Maluko

aamer4yu
29th October 2013, 14:00
What was the 281 errors you were getting ? You could post a few.

Also do mention the PATH and QTDIR values from your environment.

Maluko_Da_Tola
29th October 2013, 14:58
Hi, here are a few examples:

error: 'QLabel' does not name a type
error: call of overloaded 'qRound(int)' is ambiguous
error: forward declaration of 'class QPushButton'
error: invalid use of incomplete type 'class QLabel'
error: forward declaration of 'class QLabel'
error: type 'QLabel' is not a direct base of 'microLabel'

PATH: C:\Qt\Qt5.1.1\5.1.1\mingw48_32\bin; (I tried to add C:\Qt\4.7.4 to the PATH but the results were the same).
QTDIR: C:\Qt\Qt5.1.1\5.1.1\mingw48_32; (I tried to replace this with C:\Qt\4.7.4 but it did not run the results were the same).

Thank you,
Maluko

anda_skoa
30th October 2013, 10:57
Sounds like you are missing includes for QLabel, QPushButton and so on.

Since it builds with Qt4 one reason could be that you are using a module include and did not modify it, e.g. you have


#include <QtGui>

and have not changed it to


#include <QtWidgets>


Cheers,
_

Maluko_Da_Tola
30th October 2013, 18:48
Thank you anda_skoa: It worked! For anyone interested, I solved the error 'error: call of overloaded 'qRound(int)' is ambiguous' by assigning seting the argument to float using 'qRound(float(int))'

Many thanks
Maluko

ChrisW67
30th October 2013, 21:00
Regardless of where this error is coming from, Rounding an integer makes no sense.

Maluko_Da_Tola
30th October 2013, 22:34
ChrisW67, rounding an integer seems to be pointless, indeed. However, that is not the issue: the argument of qRound() could be L/2, where L is an integer. So, if L is an odd number, L/2 is not an integer anymore. In Qt4 there was no problems, it would recognise that L/2 would not be an integer and would round it (so the sintax qRound(L/2) would produce no errors). In Qt5 I need to declare that explicitly by writing qRound(float(L/2)).

Cheers
Maluko

ChrisW67
30th October 2013, 23:41
If you have int L then the expression L/2 results in an integer not a float.

Qt4 has only one version of qRound() taking a double, so an implicit cast of integer to double is done and qRound(L/2) compiles cleanly (although you are still "rounding" an integer).
Qt5 has two versions of qRound() taking float or double. Your compiler has raised the new error because it does not know whether to implicitly cast the integer value you have given qRound() to float or double.

Casting to a float the way you have done does not achieve what you think it does. By the time you cast to float you have already done an integer division and discarded the fractional part. There's nothing for qRound() to round even if you then cast the integer result to float or double.


int L = 5;
qDebug() << L / 3; // 1, an integer division
qDebug() << qRound(L / 3); // 1, still an integer division (will not compile under Qt5)
qDebug() << qRound(float(L / 3)); // 1, converting the integer result to float still discards the fractional part
qDebug() << qRound(L / 3.0); // 2, this is forcing floating point division
qDebug() << qRound(qreal(L) / 3); // 2, also a floating point division



If you do revert to Qt4 then you will need a suitable tool chain. The Qt4 binaries distributed at the Qt Project site were built with MingW/GCC 4.4. You appear to be using the GCC 4.8 compiler. There are, if memory serves, binary interface differences between GCC 4.4 and 4.8 that might cause unexpected runtime issues if you mix Qt objects of the old and new binary formats. If you want to use the Qt4 binaries as-is you will need to match the GCC version.

Maluko_Da_Tola
31st October 2013, 00:03
Many thanks :) a few years away from c++/Qt and I had forgot about its peculiar algebra!