移至Qt5时编译错误:尚未声明“类型”

时间:2014-03-10 07:52:50

标签: c++ qt qt5

使用Qt 5.2.1编译旧的Qt项目(可能由Qt 4.8创建): Lan messenger开源:

#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

错误:'类型'尚未声明

我不知道如何解决这些错误。 有人会帮忙吗? 谢谢。

2 个答案:

答案 0 :(得分:5)

在Qt存储库中提交引用:

  

QCoreApplication :: Type和QApplication :: type()已被删除。   这些Qt3遗留应用程序类型与Qt5中可用的应用程序类型不匹配。   例如,使用qobject_cast来动态找出确切的应用程序类型。

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

作为一种解决方法,如果你没有在QtSingleApplication构造函数中指定类型,那么你可以将它注释掉,并且在没有它的情况下仍然继续使用QtSingleApplication。

qtsingleapplication.h: 第70行:

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

qtsingleapplication.cpp: 第176行:

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

答案 1 :(得分:1)

我使用过QtSingleApplication。它是一组独立的库,用于控制来自同一可执行文件的进程数。显然,from a similar thread on Qt forum,它使用了Qt5中已弃用或删除的几个功能。您需要做的是使用更新版本替换Lan Messenger附带的版本。实际上,您可能需要提交Qt5兼容性补丁。