Some issues related to a program

  • Hello,

    Here is the program and it's its screenshot.

    Here is also the code for the showGridAction (where I see issues in that) inside the:
    void MainWindow::createActions() function (in MainWindow.cpp)

    showGridAction = new QAction(tr("&Show Grid"), this);
        showGridAction -> setCheckable(true);
        showGridAction -> setChecked(spreadsheet -> showGrid());
        showGridAction -> setStatusTip(tr("Show or hide the spreadsheet's"
                                           " grid"));
        connect(showGridAction, SIGNAL(toggled(bool)),
                spreadsheet, SLOT(setShowGride(bool)));
    #if QT_VERSION < 0x040102
        // workaround for a QTableWidget bug in Qt 4.1.1
        connect(showGridAction, SIGNAL(toggled(bool)),
                spreadsheet->viewport(), SLOT(update()));

    My questions:

    1- First I think the part #if QT_VERSION < 0x040102 until #endif is not needed anymore, because I'm using Qt 5.9. Do you think so too?

    2- That code doesn't work in effect. As you can see from the screenshot above, checking and unchecking the Show Grid option makes no changes! How to make it work for the app please?

    3- There is a slot in the code named setShowGride(bool). Where is it from? It won't be highlited when I click it and also takes me nowhere when I press F2 on it! It's probably the source of the issue for the option above not to function. How to fix it please?

  • Lifetime Qt Champion


    Yes, you can remove the code in the #if statement since you won't compile it with Qt 4.

    Are you sure it's not setShowGrid without the final e ?

  • You solved the issue, thanks. I always make typos. ;)
    Thank you very much.
    I don't know why the compiler didn't catch it as an error!

  • @tomy
    You only have the error at runtime on the console (maybe only in debug, I don't remember) as the signal/slot mechanism is not static but build at runtime. The compiler can't do anything is this case.

  • @tomy said in Some issues related to a program:

    I don't know why the compiler didn't catch it as an error!

    To catch an error like this at compile time, you should use the new connect syntax:

    connect(showGridAction, &QAction::toggled, spreadsheet, &QTableWidget::setShowGrid);

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.