0

I get LNK 2019 and LNK 1120 errors with the following c++ code. This is the error message: graphapp.obj:-1: error: LNK2019: unresolved external symbol "public: virtual __cdecl GraphApp::~GraphApp(void)" (??1GraphApp@@UEAA@XZ) referenced in function "public: virtual void * __cdecl GraphApp::`scalar deleting destructor'(unsigned int)" (??_GGraphApp@@UEAAPEAXI@Z)

The header file has no virtual declarations, so I am very confused.

#include "graphapp.h"
#include "ui_graphapp.h"

GraphApp::GraphApp(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::GraphApp)
{
    ui->setupUi(this);
    //qDebug() << "Initiate main window";
    this->setWindowTitle("Graphing");
    
    //Set up the line graph
    my_graph = new QChart();
    my_graphView = new QChartView(my_graph);
    my_graphView->setRenderHint(QPainter::Antialiasing);
    my_graphView->setParent(ui->graph_widget);
    my_graphView->setFixedSize(ui->graph_widget->size());
    my_graph->legend()->hide();
    
    //setting up the timer
    //graph_timer = new QTimer;
    //graph_timer->setInterval(100);
    //graph_timer->setSingleShot(false);
    
    QList <float> storedData = *new QList<float>;
    
    ui->pushButton->setEnabled(false);
    ui->pushButton_export->setEnabled(false);
    ui->pushButton_refresh->setEnabled(false);
    ui->pushButton_start->setEnabled(false);
    
    connect(ui->pushButton_export, SIGNAL(clicked()), SLOT(dataExport()));
    connect(ui->pushButton_refresh, SIGNAL(clicked()), SLOT(onUpdateGraph()));
    connect(ui->pushButton, SIGNAL(clicked()), SLOT(updateTable));
    connect(ui->pushButton_start, SIGNAL(clicked()), SLOT(oninitializeTimer()));
}



/**@brief Function called to collect unsigned integer array data
  *
  * @details Creates an array of arrays to store data
  *
  * @param[in] incomingData Data in form of unsigned integer arrays.
  */

void GraphApp::dataSave(float convData)
{
    ui->tableWidget->insertRow(convData);
    storedData.append(convData);
    
}
/**@brief Function exports data
   *
   * @details Creates a csv to export on press of  button
   *
   * @param[in] stored_data QList of all saved data so far
   */

void GraphApp::dataExport(QList<float> data_to_graph)
{
    std::ofstream myFile("BluetoothData.csv");
    for(int i = 0; i < data_to_graph.size(); ++i)
    {
        myFile << data_to_graph.at(i);
        if(i != data_to_graph.size() - 1) myFile << ","; // No comma at end of line
    }
    myFile << "\n";
    
    myFile.close();
    
}

/**@brief Function updates graph
   *
   * @details Refreshes the page and plots new data
   *
   */


void GraphApp::onUpdateGraph()
{
    
    if((my_graph->series()).length()>0)
    {
        my_graph->removeAllSeries();
    }
    
    my_graphSeries = new QLineSeries;
    my_graph->addSeries(my_graphSeries);
    my_graph->createDefaultAxes();
    
    my_graph->axisY()->setTitleText("Bluetooth Information");
    my_graph->axisX()->setTitleText("Device");
    
    my_graph->setTitle("Bluetooth Data");
    
    for(int r=0;r<ui->tableWidget->rowCount();r++)
    {
        
        my_graphSeries->append(r,ui->tableWidget->item(r, 0)->text().toFloat());
        
    }
}

/**@brief Function updates table
   *
   * @details Refreshes the page and makes a new table
   *
   */


void GraphApp::updateTable()
{
    float toAdd = 0.0;
    int row = 0;
    for(int i = 0, total=storedData.size(); i < total; ++i)
    {
        toAdd = storedData[i];
        ui->tableWidget->insertRow( ui->tableWidget->rowCount() );
        
        QTableWidgetItem *btitem = new QTableWidgetItem;
        btitem->setData(Qt::DisplayRole,toAdd);
        
        ui->tableWidget->setItem(row, 0, btitem);
        row++;
        
        
    }
}

/**@brief Function initiates tiner to start process of data saving
   *
   * @details Starts timer on press of the "Start" Button
   *
   */


void GraphApp::oninitializeTimer()
{
    //setting up the timer
    graph_timer = new QTimer;
    graph_timer->setInterval(1000);
    graph_timer->setSingleShot(false);
    //send out the signal that BLE handler does
    //do the data handling
    connect(graph_timer, SIGNAL(timeout()), this, SLOT(dataSave()));
    
}  

This is the header file:

#ifndef GRAPHAPP_H
#define GRAPHAPP_H

#include <QMainWindow>
#include "serialcommunicator.h"
#include "basecommunicator.h"
#include <QDebug>
#include "libs/packetprotocol/PacketProtocol.h"
#include <QSerialPort>
#include <QtCharts/QChartView>
#include <QtCharts/QLineSeries>
#include <QtCharts>
#include <QtSerialPort/QSerialPortInfo>
#include <QtSerialPort/QSerialPort>
#include <QTimer>
#include <QFile>
#include <QDateTime>
#include <QDir>
#include <QMessageBox>
#include <QVector>
#include <fstream>
#include <vector>
#include <utility>

QT_BEGIN_NAMESPACE
namespace Ui { class GraphApp; }
QT_END_NAMESPACE

class GraphApp : public QMainWindow
{
    Q_OBJECT

public:
    explicit GraphApp(QWidget *parent = 0);
    //QTimer* graph_timer;
    ~GraphApp();

private slots:
    void dataSave(float convData);
    void dataExport(QList<float> data_to_graph);
    void onUpdateGraph();
    void updateTable();
    void oninitializeTimer();

private:
    //quint32 dataConvert(QByteArray incomingData);

private:
    Ui::GraphApp *ui;
    QChartView *my_graphView;
    QChart *my_graph;
    QLineSeries *my_graphSeries;
    QList<float> storedData;
    QTimer* graph_timer;

};

#endif // GRAPHAPP_H
  • 5
    You declared this: `~GraphApp();` in your class declaration. so... where is it implemented in the source you posted? – WhozCraig Jun 20 '22 at 18:58
  • 2
    I bet `QMainWindow` has a `virtual` destructor. Edit: Yes: [~QMainWindow](https://doc.qt.io/qt-6/qmainwindow.html#dtor.QMainWindow) – Ted Lyngmo Jun 20 '22 at 19:02
  • 1
    The destructor is implicitly `virtual` because the base class destructor is `virtual`. A `virtual` destructor must always be explicitly defined if it is explicitly declared. You have explicitly provided a declaration, but apparently no definition for `~GraphApp()`. – user17732522 Jun 20 '22 at 19:04
  • 1
    If you don't need any special care in the destructor, just remove `~GraphApp();` from the class definition. – Ted Lyngmo Jun 20 '22 at 19:05
  • 1
    "The header file has no virtual declarations, so I am very confused." They are here: `: public QMainWindow`. See for example https://stackoverflow.com/questions/19199661/concept-of-virtual. – Karl Knechtel Jun 20 '22 at 19:06

0 Answers0