Qt World Summit: Submit your Presentation

Basic stuff here...

  • Hi,

    So, I'm working my way through C++ GUI Programming with Qt 4 by Blanchard and Summerfield.
    I have installed the latest version of Qt Creator (Creator 4.6.2 based on Qt 5.11.1)

    I understand that the differences between Qt 4 and Qt 5 are minimal but do exist.
    The problem is, I don't know what I don't know.

    So, working through the first chapter, I'm copying code pretty-much verbatim (apart from the odd typo here and there which, for the most part, I catch) but keep running into snags.

    I'm trying to get the GoToCell Example (Chapter 2, page 28) going... and it's like it can't see my .cpp file with the constructor as it won't allow me to declare a new class based on my defined type.
    I tried putting Ui:: in front of it to no avail.

    Is this an issue with slight variations between versions?
    Could I have made a typo someone that is stopping the compiler from seeing my class definitions?

    Any help would be appreciated!



  • Lifetime Qt Champion

    @Uberlinc said in Basic stuff here...:

    and it's like it can't see my .cpp file with the constructor as it won't allow me to declare a new class based on my defined type

    I don't understand this. Can you please explain/show what you did and what error you get?
    Also which Qt version do you use ("Creator 4.6.2 based on Qt 5.11.1" - does not tell you which Qt version you use, but which Qt version was used to build QtCreator)?

    "Basic stuff here..." - isn't a good title.

  • Hi,

    I wrote "Basic stuff here" because I'm still at the beginning of the book.
    Since then, I've made some changed from what I've found in other sources.

    It seems that I need:

    QT = core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    in the .pro file.

    Why is this?
    Is this always required?



  • Lifetime Qt Champion


    QT = core gui
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    Why is this?

    Because in Qt4 widgets was implicit when giving gui. In Qt5, both modules are separated for smaller libraries.

    Is this always required?

    If you don't need Qt4 compatibility (just use Qt5), you can just write:QT = core gui widgets

  • Lifetime Qt Champion

    Also as a note
    here you find all samples from that book
    convert to work in Qt5.

    So if u get other issues related to the changes in includes,
    you can use that as reference.

  • Thanks for this.

    I've actually been using this reference:
    .... which is essentially the same.

    When I can't get my code to go, I compare side-by-side with this to see if I can spot the typo.
    It seems that there are some small differences with the latest when compared to the book.

    I'll persevere.

    Many thanks.

  • Lifetime Qt Champion

    Ok, seems fine too :)
    its just that the other link is fixed
    so it just compiles in Qt5. including all the pro file

  • Ah! An important difference!
    I suspect that many of my woes revolve around Qt 5 compatibility so this will be of great help!

    Thank you once again!

  • Thanks for the Qt 5 code link.
    It was helpful, and I went about making changes to match Qt 5 code standard.
    However, it would seem that the code is still not working.
    I then went about copying and pasting the raw code from the website in case it was a tiny typo that I kept missing.
    Again, it gave the same error.

    (I apologise. I'm struggling here!)

    It refuses to recognise the 'buttonBox' variable in spite of:

    1. Being created in the Design Tool
    2. Being specified in the Design Tool Property Editor (yes, I checked syntax)
    3. It is clearly specified in the qmake created ui_gotocell.h file.
    4. I have ensured that the ui_gotocell.h file is included in the relevant file (and I added it to the .cpp file for good measure!)
      It keeps giving the error "buttonBox was not declared in this scope."

    I've been staring at it for hours.

    Any ideas?


  • Can you provide a link to your specific example?

  • Lifetime Qt Champion

    @Uberlinc It should be


  • Do you mean:

    #include <QtWidgets>

    #include "gotocelldialog.h"
    #include "ui_gotocelldialog.h"

    GoToCellDialog::GoToCellDialog(QWidget *parent)
    : QDialog(parent)

    QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
    lineEdit->setValidator(new QRegExpValidator(regExp, this));
    connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
    connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));


    void GoToCellDialog::on_lineEdit_textChanged()

    This yielded "Expected Primary Expression before ->"
    (as well as the original two errors.)

    I tried it with a Ui::buttonBox and it gave "buttonBox is not a member of Ui"



  • Lifetime Qt Champion


    i think something went wrong copying stuff around
    I just download the whole zip and open that project.
    and it just ran.

    so could u try try with clean project ?

  • Lifetime Qt Champion

    @Uberlinc said in Basic stuff here...:


    ui not Ui!

  • I can find the code listings, but not the zip file.
    Am I missing it here?
    Can you please provide a link?


  • Lifetime Qt Champion

  • Lifetime Qt Champion

    It uses the old ? / other way with ui
    class GoToCellDialog : public QDialog, public Ui::GoToCellDialog

  • Okay, yes the downloaded version works.

    The only thing that I can think of is that when creating the form, I selected "Dialog" instead of "Widget."
    I must have missed that the first time around.

    Would this have caused this problem?


  • Lifetime Qt Champion

    well for
    "buttonBox was not declared in this scope."
    i would guess on something with the UI and maybe left
    over files in your build folder.
    Using Dialog and not widget should not have changed the name of buttons / if it was created.

  • Okay.
    I guess this is something that will come easier to me with more experience.
    Thank you to all who assisted.

    I will push on!

  • Lifetime Qt Champion

    well push on and it will be super :)
    Sometimes one needs to clean build folder. ( as in delete all in it)

Log in to reply