Results 1 to 13 of 13

Thread: class Ui::MainWindow has no member named horizontalSlider

  1. #1
    Join Date
    Jun 2015
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default class Ui::MainWindow has no member named horizontalSlider

    I was following a signal&slot tutorial I found out on youtube on how to create a progressBar and horizontalSlider just by coding, without drag&drop.

    This is the code (mainwindow.cpp file):
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. connect(ui->horizontalSlider,
    10. SIGNAL(valueChanged(int)),
    11. ui->progressBar,
    12. SLOT(setValue(int)));
    13. }
    14.  
    15. MainWindow::~MainWindow()
    16. {
    17. delete ui;
    18. }
    To copy to clipboard, switch view to plain text mode 

    As you see, all the job was to add the text in the constructor.
    It fails to compile on my laptop: "class Ui::MainWindow has no member named horizontalSlider and class Ui::MainWindow has no member named progressBar".
    However on the video I was following it compiles and the author didn't make any additional writings.
    I would highly appreciate your suggestions, guys.
    I'm using Qt 5.4.1, maybe it's because of version inconsistencies and that tutorial is outdated?

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: class Ui::MainWindow has no member named horizontalSlider

    Open your MainWindow.ui file and look at the properties of each control on the form. Additionally, when you type ui-> and pause, you should get a code completion window which you can browse through and identify your horizontal slider control.

  3. #3
    Join Date
    Jun 2015
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: class Ui::MainWindow has no member named horizontalSlider

    This is my mainwindow.ui file:

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>MainWindow</class>
    <widget class="QMainWindow" name="MainWindow">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>300</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>MainWindow</string>
    </property>
    <widget class="QWidget" name="centralWidget"/>
    <widget class="QMenuBar" name="menuBar">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>25</height>
    </rect>
    </property>
    </widget>
    <widget class="QToolBar" name="mainToolBar">
    <attribute name="toolBarArea">
    <enum>TopToolBarArea</enum>
    </attribute>
    <attribute name="toolBarBreak">
    <bool>false</bool>
    </attribute>
    </widget>
    <widget class="QStatusBar" name="statusBar"/>
    </widget>
    <layoutdefault spacing="6" margin="11"/>
    <resources/>
    <connections/>
    </ui>

    Please, could you explain me what's going on here?

    Regarding the completion window - here is what I see:
    centralWidget
    mainToolBar
    menuBar
    retranslateUi
    setupUi
    statusBar
    MainWindow
    Ui_MainWindow.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: class Ui::MainWindow has no member named horizontalSlider

    Looks like you forgot to add both the slider and the progressbar while editing the form in designer.
    That mainwindow has an empty content widget.

    Cheers,
    _

  5. #5
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: class Ui::MainWindow has no member named horizontalSlider

    Open the file in the Designer not in a text editor. Yes, it's an XML file which describes the UI but it is not human-readable (almost ). Therefore
    (1) If you have Designer installed, run the Designer, select "Open", select your ui file.
    (2) Otherwise, open your project in the Creator, open "forms", select your ui.file.

    You will see your UI, check attributes of MainWindow and see, whwther it has the scrollbar (I am not sure it can, You will need QScrollArea for it).

  6. #6
    Join Date
    Jun 2015
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: class Ui::MainWindow has no member named horizontalSlider

    Quote Originally Posted by anda_skoa View Post
    Looks like you forgot to add both the slider and the progressbar while editing the form in designer.
    That mainwindow has an empty content widget.

    Cheers,
    _
    anda_skoa, my task was to evoid drag&drop, doing everything just by coding only.

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: class Ui::MainWindow has no member named horizontalSlider

    my task was to evoid drag&drop, doing everything just by coding only.
    If you like doing things the hard way, then


    • delete your mainwindow.ui file and ensure it is removed from the project,
    • remove the #include "ui_mainwindow.h" line,
    • remove the "Ui::MainWindow * ui" variable from your MainWindow class header,
    • remove the "ui( new Ui::Mainwindow )" initialization from the constructor
    • remove the "ui->setupUi()" line
    • remove the "connect()" line
    • remove the "delete ui;" line from the destructor
    • run qmake, then build your project


    Now you have an empty MainWindow class where you will be forced to add C++ code to create everything except those things already built into the QMainWindow class. Don't ask "Where's the horizontal slider", because there isn't any. There isn't any progress bar either. You will have a bare naked QMainWindow to which you will have to add (through code, not drag and drop) anything you want in it.

  8. The following user says thank you to d_stranz for this useful post:

    alexcodercpp (21st June 2015)

  9. #8
    Join Date
    Jun 2015
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: class Ui::MainWindow has no member named horizontalSlider

    d_stranz, I've done everything you listed out.
    Now the constructor looks this way:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent)
    3. {
    4. QProgressBar* progBar = new QProgressBar(this);
    5. QSlider* slider = new QSlider(this);
    6. }
    To copy to clipboard, switch view to plain text mode 

    Am I on the right path?

  10. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: class Ui::MainWindow has no member named horizontalSlider

    Yes, but perhaps you should read some of the material in Qt Assistant before you continue
    Address book tutorial
    Layout Examples

    You could get a hold of "C++ GUI Programming with Qt 4, 2nd Ed" by Blanchette and Summerfield. (Very little in Qt5 differs from the Qt4 examples. First Ed call be downloaded but differs more).

    Something else you could do is build a *.ui file using Designer (outside your project), run it through uic and read the output. You can see how the Designer constructs the UI you designed (it just writes code for you).
    Qt Code:
    1. C:\> designer test.ui
    2. C:\> uic test.ui > test.cpp
    3. C:\> notepad test.cpp
    To copy to clipboard, switch view to plain text mode 

  11. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: class Ui::MainWindow has no member named horizontalSlider

    Quote Originally Posted by alexcodercpp View Post
    anda_skoa, my task was to evoid drag&drop, doing everything just by coding only.
    Well, you said you are doing a signal&slot tutorial and since you were using ui-> in your connect I assumed you were doing the UI in designer.

    Not doing the signal/slot connection via designer did, for me, not imply abstaining from using the designer for creating the UI itself.

    After all, doing the UI in designer and connecting signal/slots in code is the most widely used combination in actual projects.

    Cheers,
    _

  12. #11
    Join Date
    Jun 2015
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: class Ui::MainWindow has no member named horizontalSlider

    Ok, I'm about to close this topic as solved, one question keeps me intrigued however: why in the tutorial I was following was no error ?
    https://www.youtube.com/watch?v=cy5QqXZ5RCo (voidrealms youtube channel qt playlist)
    watch it from 2m18s: he deletes progressBar and horizontalSlider and starts writing the code. Maybe I misunderstood something?

  13. #12
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: class Ui::MainWindow has no member named horizontalSlider

    Quote Originally Posted by alexcodercpp View Post
    watch it from 2m18s: he deletes progressBar and horizontalSlider
    No, he does not.
    You can clearly see that both widgets are still on the dialog form when he switches back to the code editior.

    Cheers,
    _

  14. #13
    Join Date
    Jun 2015
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: class Ui::MainWindow has no member named horizontalSlider

    Now I see. It was my lack of attention. However your answers were very informative and educational to me. Thanks to everybody.

Similar Threads

  1. Replies: 1
    Last Post: 8th March 2014, 20:03
  2. Replies: 6
    Last Post: 9th March 2013, 12:33
  3. Replies: 3
    Last Post: 12th April 2011, 10:58
  4. Class 'QWidge't has no member named 'setSize'
    By Omicron in forum Qt Programming
    Replies: 5
    Last Post: 3rd April 2011, 16:48
  5. Replies: 2
    Last Post: 29th June 2009, 06:09

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.