Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    SetupUi gives troubles with my class

    General and Desktop
    3
    5
    5196
    Loading More Posts
    • 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.
    • R
      ragnabob last edited by

      For a new project I started, I decided to use Qt, since a friend of mine kept going on about it. So, bear with me, I'm still rather new to this.

      Ok, I defined a class (in this case called DNAViewer) and I've made a nice UI using designer. So now I wish to use setupUi() and I parse it 'this' as an argument. My class is defined as
      @
      class DNAViewer : public QWidget , private Ui::DNAViewerUIDLG{
      Q_OBJECT

      public:
      DNAViewer(QWidget *parent = 0);

      ...

      };
      @

      Now, as far as I know, if I call setupUi(this) in the constructor (seen below), this should work, right?
      @
      DNAViewer::DNAViewer(QWidget *parent){
      setupUi(this); // this sets up GUI

      ...

      }
      @
      Any help would be greatly appreciated.

      1 Reply Last reply Reply Quote 0
      • G
        giesbert last edited by

        Which troubles do you get? What goes wrong?

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply Reply Quote 0
        • R
          ragnabob last edited by

          I get the following:
          _
          DNAViewer.cpp: In constructor ‘DNAViewer::DNAViewer(QWidget*)’:
          DNAViewer.cpp:6:17: error: no matching function for call to ‘DNAViewer::setupUi(DNAViewer* const)’
          ui_DNAHilbertViewerUI.h:37:10: note: candidate is: void Ui_DNAViewerUIDLG::setupUi(QDialog*)
          _

          Which I don't completely get, since there is a perfectly fine setupUi() function which takes a QWidget...

          1 Reply Last reply Reply Quote 0
          • G
            goetz last edited by

            You created a UI based on a QDialog in Qt Designer. So you must inherit from QDialog in your DNAViewer class too (instead of QWidget).

            Just change dnaviewer.h to

            @
            class DNAViewer : public QDialog , private Ui::DNAViewerUIDLG{
                Q_OBJECT
              
            public:
                DNAViewer(QWidget *parent = 0);
             
            ...
             
            };
            @

            and dnaviewr.cpp to

            @
            DNAViewer::DNAViewer(QWidget *parent)
            : QDialog(parent)
            {
                setupUi(this); // this sets up GUI
             
            ...
             
            }
            @

            Pleas do not forget to call the base class constructor with the parent! That's always necessary for QObject based classes, which include QWidget and QDialog!

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply Reply Quote 0
            • R
              ragnabob last edited by

              Problem solved, I thank you very much! Note to self: this is what I get for just starting to code without any thorough reading.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post