gpt4 book ai didi

qt - 尝试编译 Qt 应用程序时获取未解析的外部符号

转载 作者:行者123 更新时间:2023-12-02 08:46:19 27 4
gpt4 key购买 nike

我在 QtCreator (QT 4.8.2) 中创建了一个简单的 GUI 应用程序并添加了一个功能来检查网络连接:

bool MainWindow::CheckNetworkConnectivity()
{
QList<QNetworkInterface> interface = QNetworkInterface::allInterfaces();
for(int i = 0; i < interface.count();i++)
{
QNetworkInterface inface = interface.at(i);
if(inface.IsUp && !inface.IsLoopBack)
{
ui->lstLog->addItem(inface.name()+QDateTime::currentDateTime().toString("h:m:s ap"));
ui->chkConStatus->setChecked(true);
}
else{
ui->chkConStatus->setChecked(false);
}
}
return ui->chkConStatus->checkState();
}

之后,任何编译代码的尝试都会产生以下错误:

    15:21:11: Running steps for project MasterVPN...
15:21:11: Configuration unchanged, skipping qmake step.
15:21:11: Starting: "C:\Qt\Designer\bin\jom.exe"
C:\Qt\Designer\bin\jom.exe -f Makefile.Debug
cl -c -nologo -Zm200 -Zc:wchar_t- -Zi -MDd -GR -EHsc -W3 -w34100 -w34189 -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"c:\Qt\4.8.2\include\QtCore" -I"c:\Qt\4.8.2\include\QtGui" -I"c:\Qt\4.8.2\include" -I"c:\Qt\4.8.2\include\ActiveQt" -I"debug" -I"." -I"..\MasterVPN" -I"." -I"c:\Qt\4.8.2\mkspecs\win32-msvc2010" -Fodebug\ @C:\Users\Master\AppData\Local\Temp\mainwindow.obj.4156.31.jom
mainwindow.cpp
link /LIBPATH:"c:\Qt\4.8.2\lib" /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /MANIFEST /MANIFESTFILE:"debug\MasterVPN.intermediate.manifest" /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /OUT:debug\MasterVPN.exe @C:\Users\Master\AppData\Local\Temp\MasterVPN.exe.4156.5422.jom
mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QNetworkInterface::~QNetworkInterface(void)" (__imp_??1QNetworkInterface@@QAE@XZ) referenced in function "public: bool __thiscall MainWindow::CheckNetworkConnectivity(void)" (?CheckNetworkConnectivity@MainWindow@@QAE_NXZ)
mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class QString __thiscall QNetworkInterface::name(void)const " (__imp_?name@QNetworkInterface@@QBE?AVQString@@XZ) referenced in function "public: bool __thiscall MainWindow::CheckNetworkConnectivity(void)" (?CheckNetworkConnectivity@MainWindow@@QAE_NXZ)
mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QNetworkInterface::QNetworkInterface(class QNetworkInterface const &)" (__imp_??0QNetworkInterface@@QAE@ABV0@@Z) referenced in function "public: bool __thiscall MainWindow::CheckNetworkConnectivity(void)" (?CheckNetworkConnectivity@MainWindow@@QAE_NXZ)
mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class QList<class QNetworkInterface> __cdecl QNetworkInterface::allInterfaces(void)" (__imp_?allInterfaces@QNetworkInterface@@SA?AV?$QList@VQNetworkInterface@@@@XZ) referenced in function "public: bool __thiscall MainWindow::CheckNetworkConnectivity(void)" (?CheckNetworkConnectivity@MainWindow@@QAE_NXZ)
debug\MasterVPN.exe : fatal error LNK1120: 4 unresolved externals
jom: C:\Users\Master\Documents\Qt\MasterVPN-build-desktop-Qt_4_8_2__4_8_2__Debug\Makefile.Debug [debug\MasterVPN.exe] Error 1120
jom: C:\Users\Master\Documents\Qt\MasterVPN-build-desktop-Qt_4_8_2__4_8_2__Debug\Makefile [debug] Error 2
15:21:17: The process "C:\Qt\Designer\bin\jom.exe" exited with code 2.
Error while building/deploying project MasterVPN (target: Desktop)
When executing step 'Make'

谁能指出可能是什么原因?

最佳答案

链接器指示找不到所需的功能。它包含在 QtNetwork4.lib(如果您使用的是 Windows 平台)或您平台的等效库中。所以你必须告诉链接器它需要链接到这个库。网络模块是必需的,所以不仅仅是

QT += core gui

至少做到这一点

QT += core gui network

这应该可以修复您看到的链接器错误。

关于qt - 尝试编译 Qt 应用程序时获取未解析的外部符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12246491/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com