我是QT新手,请多多关照。运行项目时,我始终遇到无法解析的外部符号。我不知道在这里还能做什么。我主要是在C#上做项目,所以我只在C#中应用对象引用或声明。我一直在寻找解决方案的时间很长,但是我没有运气。
它发生在main.cpp的layer-> AddLayer()上
................................................... ................................................... ................................................... ........
这是我的Main.cpp:
#include <QCoreApplication>
#include <QFile>
#include <QXmlStreamReader>
#include <QDebug>
#include <iostream>
#include <QtGlobal>
#include <stdio.h>
#include <stdlib.h>
#include "layer.h"
QFile* xmlFile;
QXmlStreamReader* xmlReader;
Layer *layer;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
xmlFile = new QFile("D://composition.svg");
if (!xmlFile->open(QIODevice::ReadOnly | QIODevice::Text))
qDebug() << ("Load XML File Problem");
xmlReader = new QXmlStreamReader(xmlFile);
//QList<Layer> layerList;
//Parse the XML until we reach end of it
while(!xmlReader->atEnd() && !xmlReader->hasError()) {
// Read next element
QXmlStreamReader::TokenType token = xmlReader->readNext();
//If token is just StartDocument - go to next
if(token == QXmlStreamReader::StartDocument)
continue;
//If token is StartElement - read it
if(token == QXmlStreamReader::StartElement)
{
if(xmlReader->name() == "g")
{
foreach(const QXmlStreamAttribute &attr, xmlReader->attributes())
{
layer->AddLayer();
int x = 0;
if (attr.name().toString() == QLatin1String("id")){
*layer->layerId = QString(attr.value().toString());
x++;
}
}
}
if(xmlReader->name() == "polygon")
{
foreach(const QXmlStreamAttribute &attr, xmlReader->attributes())
{
if (attr.name().toString() == QLatin1String("points"))
{
//Space
//QRegExp rx("( )");
QStringList query = attr.value().toString().split(QRegExp("( )"));
//QString* pointList = new QString[query.length()];
for(int i =0; i<query.length(); i++) {
qDebug() << query[i].toLatin1();
QString x = "Hi";
}
}
}
}
}
}
return a.exec();
}
我的layer.h
#ifndef LAYER_H
#define LAYER_H
#include <QCoreApplication>
#include <QFile>
#include <QXmlStreamReader>
#include <QDebug>
#include <iostream>
#include <QtGlobal>
#include <stdio.h>
#include <stdlib.h>
class Layer
{
public:
Layer();
QString *layerId;
QList<Layer> *layerList;
void *AddLayer();
};
class Polygon
{
public:
Polygon();
QString style;
QPointF points[2];
QString polygonColor;
QList<Polygon> polygonList;
void AddPolygon();
};
#endif // LAYER_H
Layer.cpp:
#include "layer.h"
Layer::Layer()
{
}
Polygon::Polygon()
{
}
void AddLayer()
{
Layer* layer = new Layer();
//layer->layerList.append(*layer);
}
void AddPolygon()
{
Polygon* polygon = new Polygon();
polygon->polygonList.append(*polygon);
}
XMLParse.pro:
QT += core
QT -= gui
CONFIG += c++11
TARGET = XMLParse
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp \
layer.cpp
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
HEADERS += \
layer.h
最佳答案
您需要将AddLayer
定义为Layer
的成员函数。添加Layer::
void Layer::AddLayer()
{
Layer* layer = new Layer();
//layer->layerList.append(*layer);
}
关于c++ - 使用图层类时的QT无法解析的外部符号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56391985/