C++ Qt链接器错误窗口
我试图运行这段代码,但我得到的只是链接器错误,不知道该做什么,也不知道我做错了什么。我已经为此奋斗了太长时间了,非常感谢您的帮助,我可以让这件事继续下去。这也是我有史以来的第一个Qt应用程序 运行QtCreator 3.5.1,基于Qt5.5.1(MSVC 2013,32位) 编译器:微软Visual C++编译器12 操作系统:Windows 8.1 Pro 64位 我有Qt项目,其中我有文件: Hasher.hC++ Qt链接器错误窗口,c++,qt,linker,C++,Qt,Linker,我试图运行这段代码,但我得到的只是链接器错误,不知道该做什么,也不知道我做错了什么。我已经为此奋斗了太长时间了,非常感谢您的帮助,我可以让这件事继续下去。这也是我有史以来的第一个Qt应用程序 运行QtCreator 3.5.1,基于Qt5.5.1(MSVC 2013,32位) 编译器:微软Visual C++编译器12 操作系统:Windows 8.1 Pro 64位 我有Qt项目,其中我有文件: Hasher.h #ifndef HASHER_H #define HASHER_H #incl
#ifndef HASHER_H
#define HASHER_H
#include <QString>
#include <QCryptographicHash>
class Hasher : public QCryptographicHash
{
public:
Hasher(const QByteArray &data, Algorithm method); /* Constructor */
~Hasher(); /* Destructor */
QString name, output;
private:
QCryptographicHash *QCryptObject;
};
#endif // HASHER_H
main.cpp
#include "hasher.h"
/* Destructor */
Hasher::~Hasher() {
}
/*
* Constructor Hasher(QByteArray &, Algorithm) generates hash
* from given input with given algorithm-method
*/
Hasher::Hasher(const QByteArray &data, Algorithm method) {
QByteArray result = this->QCryptObject->hash(data, method);
this->output = result.toHex();
}
#include <QCoreApplication>
#include <QString>
#include <QFile>
#include <QDebug>
#include "hasher.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString fileName;
QTextStream stream(stdin);
qDebug() << "MD5 generator!" << endl;
qDebug() << "Give filename to generate checksum from: ";
fileName = stream.readLine();
QFile* file = new QFile(fileName);
if(file->open(QIODevice::ReadOnly))
{
Hasher hasher(file->readAll(), QCryptographicHash::Md5);
qDebug() << "MD5 Hash of " << fileName << " is: " << hasher.output << endl;
file->close();
}
return a.exec();
}
.pro文件
QT += core
QT -= gui
TARGET = MD5-generator
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp \
hasher.cpp
HEADERS += \
hasher.h
在
Hasher::Hasher
中,需要调用基类构造函数:
Hasher::Hasher(const QByteArray &data, Algorithm method)
: QCryptographicHash(method)
{
QByteArray result = this->hash(data, method);
this->output = result.toHex();
}
我完全不知道MSVC为什么要编译这些代码,它甚至不应该进行链接。因此,链接器错误是由于没有更新makefile和object文件造成的,因为新的
Hasher.cpp
根本不完整。在这种情况下,重建项目可能会有帮助:Clean
,运行qmake
,Build
,从头函数定义中删除Hasher::
。@William\u Wilson,虽然这是一个错误,但不会导致链接器问题。@William\u Wilson这样做了,没有帮助。@Mpak91上述代码无法编译。所以,奇怪的是,您有链接器错误。可能makefiles和object文件没有更新。您可以尝试:清理、运行qmake和构建。您应该会看到编译器错误。无论如何,您应该决定是从qcryptographicshash
生成子类,还是将其用作私有成员。如果是私人会员,则应首先告知。如果将其子类化,则不需要qcryptographicshash*QCryptObject
当然它修复了编译错误,但它不能解释链接器错误。@OrestHera我目前无法访问MSVC,但如果它按照引用的方式编译代码,我不会感到惊讶。尝试过这个,仍然是相同的错误。谢谢你的建议。
Hasher::Hasher(const QByteArray &data, Algorithm method)
: QCryptographicHash(method)
{
QByteArray result = this->hash(data, method);
this->output = result.toHex();
}