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. SetupUi gives troubles with my class

SetupUi gives troubles with my class

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 5.6k Views
  • 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 Offline
    R Offline
    ragnabob
    wrote on last edited by
    #1

    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
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      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
      0
      • R Offline
        R Offline
        ragnabob
        wrote on last edited by
        #3

        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
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          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
          0
          • R Offline
            R Offline
            ragnabob
            wrote on last edited by
            #5

            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
            0

            • Login

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