PDA

View Full Version : undefined reference to ...(loadfile)



rahulvishwakarma
12th December 2017, 08:22
hi to all, i've centos 6.6 in VM and Qt 5.2. i am building a small project having this problem



/opt/projects/Qt/find/spreadsheetmainwindow.cpp:52: error: undefined reference to `SpreadSheetMainWindow::loadFile(QString const&)'

even i have declared in header file(spreadsheetmainwindow.h)


void SpreadSheetMainWindow::open()
{
if(okToContinue())
{
QString fileName = QFileDialog::getOpenFileName(this, "OPEN SP FILES", ".",
"SpreadSheet Files (*.sp)");
if(!fileName.isEmpty())
loadFile(fileName);//here is error
}
}

and not only for this loadFile(filename) function but for most of functions declared in header file.
as in :-


undefined reference to `SpreadSheetMainWindow::setFormula(int, int, QString const&)'

header file is :-




#ifndef SPREADSHEETMAINWINDOW_H
#define SPREADSHEETMAINWINDOW_H

#include <QMainWindow>
#include <QTableWidget>
#include <QLabel>
#include <QMessageBox>
#include <QFileDialog>
#include <QCloseEvent>
#include <QClipboard>
#include <QObject>
#include <QLineEdit>
#include <QDataStream>
#include <QFile>
#include <QTableWidgetSelectionRange>

#include "sortdialog.h"
#include "gotocelldialog.h"
#include "finddialog.h"
#include "cell.h"

namespace Ui {
class SpreadSheetMainWindow;
}

class Cell;
class SpreadsheetCompare;
class gotoCellDialog;
class QTableWidget;

class SpreadSheetMainWindow : public QMainWindow//, public QTableWidget
{
Q_OBJECT

public:
bool autoRecalculate() const { return autoRecalc; }
QString currentLocation() const;
QString currentFormula() const;
QTableWidgetSelectionRange selectedRange() const;
void clear();
bool readFile(const QString &fileName);
bool writeFile(const QString &fileName);
void sort(const SpreadsheetCompare &compare);


public:
explicit SpreadSheetMainWindow(QWidget *parent = 0);
~SpreadSheetMainWindow();
void ConnectActions();

protected:
void closeEvent(QCloseEvent *event);

private slots:
void newFile();
void open();
bool save();
bool saveAs();
void find();
void goToCell();
void sort();
void about();
void openRecentFile();
void updateStatusBar();
void spreadsheetModified();

signals:

void modified();

private slots:
void somethingChanged();
public slots:
void cut();
void copy();
void paste();
void del();
void selectCurrentRow();
void selectCurrentColumn();
void recalculate();
void setAutoRecalculate(bool recalc);
void findNext(const QString &str, Qt::CaseSensitivity cs);
void findPrevious(const QString &str, Qt::CaseSensitivity cs);


private:
enum { MagicNumber = 0x7F51C883, RowCount = 999, ColumnCount = 26 };

Cell *cell(int row, int column) const;
QString text(int row, int column) const;
QString formula(int row, int column) const;
void setFormula(int row, int column, const QString &formula);

bool autoRecalc;

void configureStatusBar();

private:
Ui::SpreadSheetMainWindow *ui;
QLabel *labellocation;
QLabel *labelformula;
gotoCellDialog *dialog;

private:
void createContextMenu();
void readSettings();
void writeSettings();

bool okToContinue();
bool loadFile(const QString &fileName);
bool saveFile(const QString &fileName);
void setCurrentFile(const QString &fileName);
void updateRecentFileActions();
QString strippedName(const QString &fullFileName);

// Spreadsheet *spreadsheet;
FindDialog *findDialog;
QLabel *locationLabel;
QLabel *formulaLabel;
QStringList recentFiles;
QString curFile;
enum { MaxRecentFiles = 5 };
QAction *recentFileActions[MaxRecentFiles];
QAction *separatorAction;
QTableWidget *tablewidget;
};

class SpreadsheetCompare
{
public:
bool operator()(const QStringList &row1,
const QStringList &row2) const;

enum { KeyCount = 3 };
int keys[KeyCount];
bool ascending[KeyCount];
};


please suggest me how t recover this " undefined reference " problem.

Ginsengelf
12th December 2017, 09:22
Hi, did you implement loadFile() somewhere? The header file only tells the compiler that the function will be available during the linking stage, so you need to implement it to get rid of the "undefined reference".

Ginsengelf