I've been trying to access another class variable, but I can't build the project. QtCreator doesn't show any error / alert. I'm trying to create a ToDo app as a University project and I need to access the name of the list to link the task to the list.
I'm sorry for this very simple question but I'm starting out both with C++ and Qt. I have already checked similar questions, but none of the answers work for me (100% my fault).
These are some code snippets:
ListManager.h
public:
static QStringList listName;
ListManager.cpp
void ListManager::on_pushButton_addList_clicked(){
QString nameList = QInputDialog::getText(this, tr("Add list"), tr("List name"), QLineEdit::Normal, tr("Untitled list"), &ok);
listName += nameList; // saves the name of the list in a QStringList
}
In the class TaskManager.cpp I want to access the names to set the QComboBox labels.
TaskManager.cpp
#include "listmanager.h"
// more code
void ListManager::on_pushButton_addTask_clicked(){
QStringList listsNames = ListManager::listName;
addTaskDialog.comboBox->addItems(listsNames);
}
As I mentioned before I don't get any error / alert by both QtCreator & CppCheck. When I try to build the program I get these issues:
error: Undefined symbols for architecture arm64:
"ListManager::listName", referenced from:
ListManager::on_pushButton_addList_clicked() in listmanager.o
TaskManager::on_pushButton_addTask_clicked() in taskmanager.o
error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [ToDoApp.app/Contents/MacOS/ToDoApp] Error 1
Any help would be much appreciated!