Abednego Js
Abednego Js

Reputation: 53

Compilation error when moving to Qt5 : 'Type' has not been declared

Use Qt 5.2.1 to compile old Qt Project (maybe created by Qt 4.8): Lan messenger open source:

#ifndef QTSINGLEAPPLICATION_H
#define QTSINGLEAPPLICATION_H

#include <QApplication>

class QtLocalPeer;

#if defined(Q_WS_WIN) || defined(Q_OS_WIN32)
#  if !defined(QT_QTSINGLEAPPLICATION_EXPORT) && !defined(QT_QTSINGLEAPPLICATION_IMPORT)
#    define QT_QTSINGLEAPPLICATION_EXPORT
#  elif defined(QT_QTSINGLEAPPLICATION_IMPORT)
#    if defined(QT_QTSINGLEAPPLICATION_EXPORT)
#      undef QT_QTSINGLEAPPLICATION_EXPORT
#    endif
#    define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllimport)
#  elif defined(QT_QTSINGLEAPPLICATION_EXPORT)
#    undef QT_QTSINGLEAPPLICATION_EXPORT
#    define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllexport)
#  endif
#else
#  define QT_QTSINGLEAPPLICATION_EXPORT
#endif

class QT_QTSINGLEAPPLICATION_EXPORT QtSingleApplication : public QApplication
{ Q_OBJECT

public:
QtSingleApplication(int &argc, char **argv, bool GUIenabled = true);
QtSingleApplication(const QString &id, int &argc, char **argv);
QtSingleApplication(int &argc, char **argv, Type type);
#if defined(Q_WS_X11)
QtSingleApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0);
QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0);
QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv,     Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0);
#endif

bool isRunning();
QString id() const;

void setActivationWindow(QWidget* aw, bool activateOnMessage = true);
QWidget* activationWindow() const;

// Obsolete:
void initialize(bool dummy = true)
    { isRunning(); Q_UNUSED(dummy) }

public Q_SLOTS:
bool sendMessage(const QString &message, int timeout = 5000);
void activateWindow();


Q_SIGNALS:
void messageReceived(const QString &message);


private:
void sysInit(const QString &appId = QString());
QtLocalPeer *peer;
QWidget *actWin;
};

#endif // QTSINGLEAPPLICATION_H

error: 'Type' has not been declared

I dont know how to fix these error. Will anyone help? Thank you.

Upvotes: 2

Views: 3176

Answers (2)

user1145065
user1145065

Reputation: 293

Quote from commit in Qt repository :

QCoreApplication::Type and QApplication::type() have been removed. These Qt3 legacy application types did not match the application types available in Qt5. Use for example qobject_cast instead to dynamically find out the exact application type.

https://qt.gitorious.org/qt/qtbase/commit/553e216d891177ee0c2cea70bbd7f21103fc7795.

As a workaround if you don't specify the type in your QtSingleApplication constructor then you can comment it out and still keep using QtSingleApplication without it.

qtsingleapplication.h: line 70:

//QtSingleApplication(int &argc, char **argv, Type type);

qtsingleapplication.cpp: line 176:

/*QtSingleApplication::QtSingleApplication(int &argc, char **argv, Type type) : 
QApplication(argc, argv, type)
{
    sysInit();
}*/

Upvotes: 7

UmNyobe
UmNyobe

Reputation: 22890

I have used QtSingleApplication. It is a separate set of libraries used to control the number of processes from the same executable. Apparently, from a similar thread on Qt forum, it uses several features which have been deprecated or removed in Qt5. What you need to do is replace the version which come with your Lan messenger with the updated version. Actually you may want to submit a patch for Qt5 compatibility.

Upvotes: 1

Related Questions