Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Basic stuff here...
Forum Updated to NodeBB v4.3 + New Features

Basic stuff here...

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 5 Posters 3.2k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Uberlinc

    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?

    Thanks.

    Uberlinc.

    aha_1980A Offline
    aha_1980A Offline
    aha_1980
    Lifetime Qt Champion
    wrote on last edited by
    #4

    @Uberlinc

    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

    Qt has to stay free or it will die.

    1 Reply Last reply
    5
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #5

      @Uberlinc
      hi
      Also as a note
      here you find all samples from that book
      https://github.com/mutse/qt5-book-code
      convert to work in Qt5.

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

      1 Reply Last reply
      6
      • U Offline
        U Offline
        Uberlinc
        wrote on last edited by
        #6

        Thanks for this.

        I've actually been using this reference:
        https://github.com/GaoHongchen/CPPGUIProgrammingWithQt4
        .... 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.

        mrjjM 1 Reply Last reply
        2
        • U Uberlinc

          Thanks for this.

          I've actually been using this reference:
          https://github.com/GaoHongchen/CPPGUIProgrammingWithQt4
          .... 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.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #7

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

          1 Reply Last reply
          2
          • U Offline
            U Offline
            Uberlinc
            wrote on last edited by
            #8

            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!

            1 Reply Last reply
            0
            • U Offline
              U Offline
              Uberlinc
              wrote on last edited by
              #9

              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?

              Thanks.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                MrShawn
                wrote on last edited by
                #10

                Can you provide a link to your specific example?

                1 Reply Last reply
                1
                • U Offline
                  U Offline
                  Uberlinc
                  wrote on last edited by
                  #11

                  https://github.com/mutse/qt5-book-code/tree/master/chap02/gotocell3

                  jsulmJ 1 Reply Last reply
                  0
                  • U Uberlinc

                    https://github.com/mutse/qt5-book-code/tree/master/chap02/gotocell3

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #12

                    @Uberlinc It should be

                    ui->buttonBox
                    

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    1
                    • U Offline
                      U Offline
                      Uberlinc
                      wrote on last edited by
                      #13

                      Do you mean:

                      #include <QtWidgets>

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

                      GoToCellDialog::GoToCellDialog(QWidget *parent)
                      : QDialog(parent)
                      {
                      setupUi(this);
                      Ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);

                      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()
                      {
                      Ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
                      lineEdit->hasAcceptableInput());
                      }

                      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"

                      Suggestions?

                      Thanks.

                      mrjjM jsulmJ 2 Replies Last reply
                      0
                      • U Uberlinc

                        Do you mean:

                        #include <QtWidgets>

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

                        GoToCellDialog::GoToCellDialog(QWidget *parent)
                        : QDialog(parent)
                        {
                        setupUi(this);
                        Ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);

                        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()
                        {
                        Ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
                        lineEdit->hasAcceptableInput());
                        }

                        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"

                        Suggestions?

                        Thanks.

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #14

                        @Uberlinc

                        Hi
                        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 ?

                        1 Reply Last reply
                        1
                        • U Uberlinc

                          Do you mean:

                          #include <QtWidgets>

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

                          GoToCellDialog::GoToCellDialog(QWidget *parent)
                          : QDialog(parent)
                          {
                          setupUi(this);
                          Ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);

                          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()
                          {
                          Ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
                          lineEdit->hasAcceptableInput());
                          }

                          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"

                          Suggestions?

                          Thanks.

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #15

                          @Uberlinc said in Basic stuff here...:

                          Ui

                          ui not Ui!

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          mrjjM 1 Reply Last reply
                          0
                          • U Offline
                            U Offline
                            Uberlinc
                            wrote on last edited by
                            #16

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

                            Thanks.

                            mrjjM 1 Reply Last reply
                            0
                            • U Uberlinc

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

                              Thanks.

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #17

                              @Uberlinc
                              alt text

                              1 Reply Last reply
                              3
                              • jsulmJ jsulm

                                @Uberlinc said in Basic stuff here...:

                                Ui

                                ui not Ui!

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #18

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

                                1 Reply Last reply
                                0
                                • U Offline
                                  U Offline
                                  Uberlinc
                                  wrote on last edited by
                                  #19

                                  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?

                                  Thanks.

                                  mrjjM 1 Reply Last reply
                                  0
                                  • U Uberlinc

                                    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?

                                    Thanks.

                                    mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on last edited by mrjj
                                    #20

                                    @Uberlinc
                                    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.

                                    1 Reply Last reply
                                    0
                                    • U Offline
                                      U Offline
                                      Uberlinc
                                      wrote on last edited by
                                      #21

                                      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!

                                      mrjjM 1 Reply Last reply
                                      0
                                      • U Uberlinc

                                        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!

                                        mrjjM Offline
                                        mrjjM Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #22

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

                                        1 Reply Last reply
                                        0

                                        • Login

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • Users
                                        • Groups
                                        • Search
                                        • Get Qt Extensions
                                        • Unsolved