5

So, I'm reading this book: C++ GUI Programming with Qt 4, Second Edition by Jasmin Blanchette; Mark Summerfield, in order to learn GUI programming. And while following thew book's steps to create a simple spreadsheet application I get an "undefined reference" error when I try to compile the Spreadsheet widget.

All the errors seem to be originated from the Cell *Spreadsheet::cell(int row, int column) function:

Cell *Spreadsheet::cell(int row, int column) const
{
    return static_cast<Cell *>(item(row, column));
}

This is the first function that complains from spreadsheet.cpp

QString Spreadsheet::formula(int row, int column) const {
    Cell *c = cell(row, column);
    if (c) {
        return c->formula();
    } else {
        return "";
    }
}

Where the line Cell *c = cell(row, column); Sends the error: /home/axel/QtSDK/Code/Spreadsheet/spreadsheet.cpp:-1: error: undefined reference to `Cell::Cell()'

This keeps happening everywhere that cell(row, column) is called. The function in itself is defined in the spreadhseet header in the private section as: Cell *cell(int row, int column) const;

Sorry if it seems messy I'm kinda new to C++ programming.

Here's my .pro file

TEMPLATE = app
CONFIG += console
CONFIG += qt

SOURCES += main.cpp \
           spreadsheet.cpp

HEADERS += \
           spreadsheet.h

If I'm missing something I'll add it as soon as I can.

Thanks, Axel

2
  • 1
    What does your .pro file look like? Commented Mar 10, 2012 at 2:38
  • 1
    Added the .pro file ^^ Commented Mar 10, 2012 at 2:44

1 Answer 1

6

Definition of the Cell class is absent. It should be cell.h at least and it should be included in spreadsheet.cpp or its code could be directly included in spresheed.h or .cpp which is less probable. Anyway the error means missing of the Cell constructor.

Sign up to request clarification or add additional context in comments.

3 Comments

Well I have #include "../cell/cell.h" in the include section of my spreadsheet.cpp, or should I include another reference to cell.h?
Add the files cell.h and cell.cpp in the project. To do that click right button on the root of the project tree (the left panel) and choose add existing files
Congrats! Then please check my answer accepted by pressing big green V and have a fun with QT and c++ ))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.