所以我想使用json文件进行应用程序,但是当我从班级中调用函数时,出现LNK2019错误。我尝试删除.pro文件,清除所有文件,运行qmake等。所有这些都不起作用
Mainwindow的行为类似于main.cpp。在main.cpp中,我仅制作了新的mainwindow对象。
Mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "taskdialog.h"
#include "task.h"
#include <QWidget>
#include "json.h"
#include <iostream>
#include <fstream>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow), nightModeIconOn(":/res/icons/switchON256.png"), nightModeIconOff(":/res/icons/switchOFF256.png"),
nightMode(false)
{
ui->setupUi(this);
ui->stackedWidget->setCurrentIndex(StackedIndex::KANBAN);
taskManagement = new TaskManagement(ui->centralVLayout_Todo, ui->centralVLayout_InProgress, ui->centralVLayout_Done);
json test("test2.json");
QJsonDocument tmp=test.makeJsondocument("test1","test2");
}
json.cpp
#include "json.h"
json::json(QString name)
{
QFile file(name);
json::fileName=name;
}
QJsonDocument makeJsondocument(QString test1, QString test2)
{
QJsonArray array={1, test1};
QJsonDocument tmp(array);
return tmp;
}
void saveJson(QJsonDocument document, QString fileName) {
QFile jsonFile(fileName);
jsonFile.open(QFile::WriteOnly);
jsonFile.write(document.toJson());
}
错误就像:
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl json::~json(void)" (??1json@@QEAA@XZ) call in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QEAA@PEAVQWidget@@@Z)