我在QT创建者5中得到一个未解析的外部符号。这个问题是我在之前已经使用过这些函数之后就开始出现这个错误了。我做了一些重构,然后,繁荣,未解决的外部符号。我尝试跟随其他许多其他人遇到QT Creator 5遇到同样问题的建议,但这似乎没有解决我的问题。
我得到的错误是:
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl QTableWidget::setRowCount(unsigned __int64)" (__imp_?setRowCount@QTableWidget@@QEAAX_K@Z) referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QEAA@PEAVQWidget@@@Z)
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl QTableWidget::setColumnCount(unsigned __int64)" (__imp_?setColumnCount@QTableWidget@@QEAAX_K@Z) referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QEAA@PEAVQWidget@@@Z)
我在编译mainwindow.cpp文件时遇到了这些错误。当您单击IDE中的错误消息时,错误消息显示为“找不到文件:mainwindow.obj”。但是,我去了build文件夹,文件就在那里。我删除了build文件夹并重建了。为了让我的项目进入与我发生变化之前相同的状态,我尝试了“非制造”一点,但这没有任何帮助。我再次尝试运行qmake,这没有用。还有其他建议吗?
我包括mainwindow.cpp文件,mainwindow.h和.pro文件,以显示我是如何使用它们的。
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <qtreewidget.h>
#include <QtDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
CurrentlySelectedAccount( nullptr )
{
financials::TheCalculator* calc = new financials::TheCalculator();
QString filename( "C:\\source\\QT_Projects\\FinancialExplorer\\InputFinancials.ini" );
calc->ParseInputFile( filename );
this->CurrentSimulation = calc;
ui->setupUi(this);
ui->Accounts->setAnimated( true );
auto AccountsMap = calc->GetAccounts();
auto iter = AccountsMap.begin();
QTreeWidget* accounts = ui->Accounts;
bool isFirst = true;
auto selectedIter = AccountsMap.begin();
while( iter != AccountsMap.end() )
{
QTreeWidgetItem* item = new QTreeWidgetItem( accounts, 2 ); // 2 means "Don't show expander if no children"
item->setText( 0, calc->GetName() );
// add properties
QTreeWidgetItem* StartDateItem = new QTreeWidgetItem( item, 0 );
QString startDateLabel( "Start Date:" );
startDateLabel.append( calc->GetStartDate().toString());
StartDateItem->setText( 0, startDateLabel );
QTreeWidgetItem* EndDateItem = new QTreeWidgetItem( item, 0 );
QString EndDateLabel( "End Date:" );
EndDateLabel.append( calc->GetEndDate().toString());
EndDateItem->setText( 0, EndDateLabel );
QTreeWidgetItem* CurrentDateItem = new QTreeWidgetItem( item, 0 );
QString CurrentDateLabel( "Current Date:" );
CurrentDateLabel.append( calc->GetCurrentDate().toString());
CurrentDateItem->setText( 0, CurrentDateLabel );
// add accounts
QTreeWidgetItem* accountsItem = new QTreeWidgetItem( item, 2 );
accountsItem->setText( 0, "Accounts" );
for( auto& account : calc->GetAccounts() )
{
QTreeWidgetItem* accItem = new QTreeWidgetItem( accountsItem, 2 );
accItem->setText( 0, account.second.GetName() );
accItem->setText( 1, "I'm an account description" );
}
// add events
QTreeWidgetItem* eventsItem = new QTreeWidgetItem( item, 2 );
eventsItem->setText( 0, "Events" );
for( auto& event : calc->GetEvents() )
{
QTreeWidgetItem* eventItem = new QTreeWidgetItem( eventsItem, 2 );
eventItem->setText( 0, event.GetName() );
eventItem->setText( 1, "I'm an event description" );
}
item->setText(1, "I'm a description");
if( isFirst )
{
item->setSelected( true );
selectedIter = iter;
isFirst = false;
}
++iter;
}
connect(ui->Accounts,&QTreeWidget::itemClicked,this,&MainWindow::on_MyTree_itemClicked);
RefreshTable();
}
void MainWindow::RefreshTable()
{
financials::TheCalculator* calc = CurrentSimulation;
if( calc != nullptr )
{
int lengthOfSimulation = calc->GetLengthOfSimulation();
ui->Spreadsheet->setRowCount( lengthOfSimulation );
int accountsSize = calc->GetAccounts().size();
ui->Spreadsheet->setColumnCount( accountsSize );
int rowIndex = 0;
while( calc->IsRunning() )
{
QString value;
auto accounts = calc->GetAccounts();
auto accountsIter = accounts.begin();
int colIndex = 0;
while( accountsIter != accounts.end() )
{
value = QString::number( (*accountsIter).second.GetCurrentBalance() );
ui->Spreadsheet->setItem(rowIndex, colIndex++, new QTableWidgetItem( value ));
++accountsIter;
}
calc->IncrementMonth();
++rowIndex;
}
}
}
void MainWindow::on_MyTree_itemClicked ( QTreeWidgetItem * item, int column )
{
qDebug() << "on_MyTree_itemClicked"
<< item->text(column);
//to do somthing
QString text = item->text(column);
if( CurrentSimulation != nullptr )
{
auto iter = CurrentSimulation->GetAccounts().find( text );
if( iter != CurrentSimulation->GetAccounts().end() )
{
if( CurrentAccountName != text )
{
CurrentAccountName = text;
CurrentlySelectedAccount = &((*iter).second);
RefreshTable();
}
}
}
}
MainWindow::~MainWindow()
{
delete ui;
}
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTreeWidgetItem>
#include <QTableWidget>
#include "thecalculator.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void on_MyTree_itemClicked ( QTreeWidgetItem * item, int column );
void Ondoubleclicktree(QModelIndex);
void update(QModelIndex);
void RefreshTable();
private:
Ui::MainWindow *ui;
QString CurrentAccountName;
financials::TheCalculator* CurrentSimulation;
financials::Account* CurrentlySelectedAccount;
};
#endif // MAINWINDOW_H
#-------------------------------------------------
#
# Project created by QtCreator 2015-08-26T18:06:52
#
#-------------------------------------------------
QT += core gui widgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = FinancialExplorer
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
accounts.cpp \
thecalculator.cpp \
financials.cpp \
events.cpp
HEADERS += mainwindow.h \
accounts.h \
financials.h \
thecalculator.h \
events.h \
qstringhashfunction.h
FORMS += mainwindow.ui
DISTFILES += \
InputFinancials.ini
答案 0 :(得分:0)
我遇到了一种情况。最后,我发现它是DefaultQtVersion和QtModules,我应该使用msvc2015_64而不是msvc2015并选择带有串行端口的模块。