我試圖調用另一個類書籤的方法,但是當我構建我的程序時我總是收到LNK錯誤,我不明白爲什麼。LNK嘗試繼承時出現Qt錯誤?
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: class QStringList __cdecl Bookmarks::getList(void)" ([email protected]@@[email protected]@XZ) referenced in function "private: void __cdecl MainWindow::on_save_book_clicked(void)" ([email protected]@@AEAAXXZ)
debug\WebBrowser.exe:-1: error: LNK1120: 1 unresolved externals
當然,第二個錯誤的存在是因爲第一個錯誤,至少我知道的很多。
我宣佈我的頭,包括我想使用類:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "bookmarks.h"
這是我想要使用的擴展槽:
void MainWindow::on_save_book_clicked()
{
Bookmarks *bm = new Bookmarks();
QStringList book = bm -> getList();
QFileDialog *fd = new QFileDialog;
QString fileName = fd -> getSaveFileName(this,
tr("Save Bookmarks"), "",
tr("Bookmarks (*.txt);;AllFiles (*)"));
if (fileName.isEmpty())
{
return;
}
else
{
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly))
{
QMessageBox::information(this, tr("Unable to open file"), file.errorString());
}
return;
QDataStream out(&file);
out.setVersion(QDataStream::Qt_4_5);
out << bm;
}
}
我確定已經錯誤來自行:
QStringList book = bm -> getList();
當我評論它,我不再收到鏈接錯誤,雖然我沒有一個線索是什麼問題造成的。爲什麼是這樣?
是在共享庫中定義的Bookmark類嗎?實際定義了getList()函數嗎? – vahancho
如果不知道項目結構,鏈接器錯誤很難解決。你必須問自己,鏈接器是否可以訪問'bookmarks.cpp'或'bookmarks.lib'(我想這就是它的名稱),找出這個問題的好方法是調用另一個'Bookmarks'函數,看看是否作品。 –
你創建書籤類後運行qmake嗎? – UldisK