Some errors in a program I'm developing

  • Hi all,

    I'm using the book C++-GUI-Programming-with-Qt-4-2nd Edition, and trying to create a spreadsheet application.
    That application occupies two chapters (3 and 4) of that book and I have prepared the files and codes in a project named MainWindow.
    There are some errors and I want to pose one of them each time so that I will make the app run successfully finally.
    Thanks for your help.

    The first error says the following in the main.cpp file:

    C:\Users\Abbasi\Documents\Qt\MainWindow\MainWindow\main.cpp:8: error: 'QSplashScreen' was not declared in this scope
    splash = new QSplashScreen;

    What .cpp or .h file should I check and remove the error please?

  • Hi,
    To be able to use 'QSplashScreen ' you have to include it like this :
    #include <QSplashScreen>


  • Thank you. The issue is solved.
    I have another error belonging to two functions, loadModules() and establishConnections(), lines 20 and 24 of the screenshot.

    They say:

    C:\Users\Abbasi\Documents\Qt\MainWindow\MainWindow\main.cpp:21: error: 'loadModules' was not declared in this scope

    C:\Users\Abbasi\Documents\Qt\MainWindow\MainWindow\main.cpp:25: error: 'establishConnections' was not declared in this scope

    I looked the functions here to find the header files to include, but didn't find.

  • Lifetime Qt Champion

    @tomy said in Some errors in a program I'm developing:


    I think they are part of the sample. Not Qt.
    But seems not to be included in the book ?!?

    Maybe they are in the full source code

    Update: Nope. The source does not contain those calls at all.

  • I made those two functions be comments because they don't seem to be needed to the app.

    My other error in mainwindow.cpp is this.
    The error:

    C:\Users\Abbasi\Documents\Qt\MainWindow\MainWindow\mainwindow.cpp:26: error: 'setWindowIdon' was not declared in this scope

    Although I included the QIcon header file, the problem still exists. :(

  • Lifetime Qt Champion

    @tomy said in Some errors in a program I'm developing:



    You have a typo: it's setWindowIcon.

  • @SGaist

    Yes, I had many other typos too. :) I corrected them. Thanks.
    Now the compiler shows only one error which belongs to the
    void MainWindow::sort() function in mainwindow.cpp.
    There are two codes in the book each with its error!

    The first code is:

    void MainWindow::sort()
        SortDialog dialog(this);
        QTableWidgetSelectionRange range = spreadsheet -> selectedRange();
        dialog.setColumnRange('A' + range.leftColumn(),
                              'A' + range.rightColumn());
            spreadsheet -> performSort(dialog.comparisonObject());

    The errors:

    error: 'class Spreadsheet' has no member named 'performSort'
    spreadsheet -> performSort(dialog.comparisonObject());

    error: 'class SortDialog' has no member named 'comparisonObject'
    spreadsheet -> performSort(dialog.comparisonObject());

    The second code:

    void MainWindow::sort()
        SortDialog dialog(this);

    And the error:
    error: 'class SortDialog' has no member named 'setSpreadsheet'

    The errors are clear. The invoked functions don't exist in the corresponding classes.

    But why has the author written such codes? And how to solve them please?

  • Lifetime Qt Champion

    What is the implementation of SortDialog ?

  • It's sortdialog.cpp:

    #include <QtWidgets>
    #include "sortdialog.h"
    SortDialog::SortDialog(QWidget* parent)
        : QDialog(parent)
        secondaryGroupBox -> hide();
        tertiaryGroupBox -> hide();
        layout() -> setSizeConstraint(QLayout::SetFixedSize);
        setColumnRange('A', 'Z');
    void SortDialog::setColumnRange(QChar first, QChar last)
      primaryColumnCombo -> clear();
      secondaryColumnCombo -> clear();
      tertiaryColumnCombo -> clear();
      secondaryColumnCombo -> addItem(tr("None"));
      tertiaryColumnCombo -> addItem(tr("None"));
      primaryColumnCombo -> setMinimumSize(
                 secondaryColumnCombo -> sizeHint());
      QChar ch = first;
      while(ch <= last)
          primaryColumnCombo -> addItem(QString(ch));
          secondaryColumnCombo -> addItem(QString(ch));
          tertiaryColumnCombo -> addItem(QString(ch));
          ch = ch.unicode() + 1;

    It has no setSpreadsheet function. So why has the book written that function for use!? :(

  • Lifetime Qt Champion

    Isn't it rather the FilterDialog class and the function is initFromSpreadsheet ?

  • Lifetime Qt Champion

    When such errors, why dont you check with the supplied source code ?
    The spreadsheet is chap03.

  • Hi,

    Thank you. I ran the supplied code and with some modifications it worked successfully.
    Now I'm at the beginning of chapter 5. The spreadsheet program is of chapters 3 and 4. Honestly speaking the code is very huge for a learner of Qt "at this point". although I have good experience of C++, it still needs much work to master the code completely. It contains more than 1500 lines of code!!

    Since my goal is continuing Qt, I think I should by no way omit this subject and should completely understand the application. It's vast but I want to start it by reading and thinking about the codes for each header and .cpp file there.
    Do you agree?
    Do you want to add some comment for helping me?


Log in to reply