Reputation: 21
I'm trying to set widget's layout by setLayout by function and i recive error messages:
main.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl LayoutManager::LayoutManager(void)" (??0LayoutManager@@QEAA@XZ) referenced in function main
main.obj:-1: error: LNK2019: unresolved external symbol "public: class QVBoxLayout * __cdecl LayoutManager::setHelloLayout(void)" (?setHelloLayout@LayoutManager@@QEAAPEAVQVBoxLayout@@XZ) referenced in function main
main.cpp
int main(int argc, char *argv[]){
QApplication app(argc, argv);
MainWindow mWin; //main widget
LayoutManager *LayMan = new LayoutManager();
mWin.setLayout(LayMan->setHelloLayout());
mWin.show();
return app.exec();
}
layoutmanager.h
class LayoutManager : public MainWindow
{
Q_OBJECT
void (*set_Lo_Pt[LAST_LAYOUT])(MainWindow&);
public:
LayoutManager();
~LayoutManager();
QVBoxLayout* setHelloLayout();
};
And here is setHelloLayout() function
QVBoxLayout* LayoutManager::setHelloLayout(){
QVBoxLayout *menuOptions = new QVBoxLayout();
QPushButton *but_HouseManager = new QPushButton("HouseManager");
QPushButton *but_Help = new QPushButton("Help");
QPushButton *but_Quit = new QPushButton("Quit");
menuOptions->addWidget(but_HouseManager);
menuOptions->addWidget(but_Help);
menuOptions->addWidget(but_Quit);
return menuOptions;
}
Class MainWindow is derived from QWidget
Is it problem with function body or I should change whole layout changing system?
Here is Compile Output
21:18:33: Running steps for project HM...
21:18:33: Configuration unchanged, skipping qmake step.
21:18:33: Starting: "D:\Qt\Tools\QtCreator\bin\jom.exe"
D:\Qt\Tools\QtCreator\bin\jom.exe -f Makefile.Debug
link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:debug\HM.exe @C:\Users\MICHA~1\AppData\Local\Temp\HM.exe.4644.15.jom
main.obj : error LNK2019: unresolved external symbol "public: __cdecl LayoutManager::LayoutManager(void)" (??0LayoutManager@@QEAA@XZ) referenced in function main
main.obj : error LNK2019: unresolved external symbol "public: class QVBoxLayout * __cdecl LayoutManager::setHelloLayout(void)" (?setHelloLayout@LayoutManager@@QEAAPEAVQVBoxLayout@@XZ) referenced in function main
debug\HM.exe : fatal error LNK1120: 2 unresolved externals
jom: D:\Qt\build-HM-Desktop_Qt_5_5_1_MSVC2013_64bit-Debug\Makefile.Debug [debug\HM.exe] Error 1120
jom: D:\Qt\build-HM-Desktop_Qt_5_5_1_MSVC2013_64bit-Debug\Makefile [debug] Error 2
21:18:33: The process "D:\Qt\Tools\QtCreator\bin\jom.exe" exited with code 2.
Error while building/deploying project HM (kit: Desktop Qt 5.5.1 MSVC2013 64bit)
When executing step "Make"
21:18:33: Elapsed time: 00:00.
This is .pro file
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = HM
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
layoutmanager.cpp
HEADERS += mainwindow.h \
layoutmanager.h
Upvotes: 1
Views: 130
Reputation: 2138
a. Please check the file-name for the cpp file containing the setHelloLayout() and the ctor - and compare it with what is in the .pro file. Both linker errors are with the same class's functions (and all needed functions fail linkage) - this means the CU for the class definition isn't being picked up.
b. With newly added/renamed files, qmake sometimes fails to pick up dependencies (and worse, refuses to remove old intermediates and links to them) - (i.e. the decision to "Configuration Unchanged - skipping qmake step" may be wrong). If you've recently renamed the file / class, please make a clean build (remove mocs & object files) and run qmake again.
Upvotes: 0
Reputation: 21
I've added a few modules to .pro file like multimedia, quick, widgets then builded it and it works. I don't know how does it work because after that I removed one after one and when I builded without these modules again it's still working. It seems like a bug for me (I'm doing everything in QTCreator) or I just don't understand how exactly compilator works.
Upvotes: 1
Reputation: 10137
Looks more like a problem with your link command. Can you update your question with your build tool's output for the link command? It would seem that you are missing the object file for the .cpp file that provides the implementation of your LayoutManager
class.
Upvotes: 0