Results 1 to 3 of 3

Thread: Problem accesing to the widgets inside a UI.

  1. #1
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Problem accesing to the widgets inside a UI.

    Hi,

    in my application the ui is not able to reach the buttons it has inside, and I don't understand why. I've done some similar applications and I never had a problem...

    I'm just adding two button to the ui file, using the Qt Creator, but the message "class xxx has no member called" is shown. I'm pretty sure it's a stupid mistake but I'm not able to figure out what can be happening. I've tried recompiling few times, delenting manually the files (tmp, moc...), deleting the ui file and creating again from the start, removing it from the project and adding it again...

    UI file
    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>CanicasClass</class>
    4. <widget class="QMainWindow" name="CanicasClass">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>270</width>
    10. <height>202</height>
    11. </rect>
    12. </property>
    13. <property name="windowTitle">
    14. <string>Canicas</string>
    15. </property>
    16. <widget class="QWidget" name="centralWidget">
    17. <layout class="QGridLayout" name="gridLayout">
    18. <item row="0" column="0">
    19. <widget class="QFrame" name="m_wdgChoseLvl">
    20. <property name="frameShape">
    21. <enum>QFrame::StyledPanel</enum>
    22. </property>
    23. <property name="frameShadow">
    24. <enum>QFrame::Sunken</enum>
    25. </property>
    26. <layout class="QGridLayout" name="gridLayout_2">
    27. <item row="0" column="0">
    28. <widget class="QScrollArea" name="m_scrollArea">
    29. <property name="verticalScrollBarPolicy">
    30. <enum>Qt::ScrollBarAlwaysOff</enum>
    31. </property>
    32. <property name="widgetResizable">
    33. <bool>true</bool>
    34. </property>
    35. <widget class="QWidget" name="scrollAreaWidgetContents">
    36. <property name="geometry">
    37. <rect>
    38. <x>0</x>
    39. <y>0</y>
    40. <width>226</width>
    41. <height>140</height>
    42. </rect>
    43. </property>
    44. <layout class="QVBoxLayout" name="verticalLayout">
    45. <item>
    46. <widget class="QPushButton" name="m_btnLevel1">
    47. <property name="text">
    48. <string>Rising Star</string>
    49. </property>
    50. </widget>
    51. </item>
    52. <item>
    53. <widget class="QPushButton" name="m_btnLevel2">
    54. <property name="text">
    55. <string>Level 2</string>
    56. </property>
    57. </widget>
    58. </item>
    59. </layout>
    60. </widget>
    61. </widget>
    62. </item>
    63. </layout>
    64. </widget>
    65. </item>
    66. </layout>
    67. </widget>
    68. <widget class="QStatusBar" name="statusBar"/>
    69. </widget>
    70. <layoutdefault spacing="6" margin="11"/>
    71. <resources/>
    72. <connections/>
    73. </ui>
    To copy to clipboard, switch view to plain text mode 


    .h code
    Qt Code:
    1. #ifndef CANICAS_H
    2. #define CANICAS_H
    3.  
    4. #include <QtGui/QMainWindow>
    5. #include "ui_canicas.h"
    6.  
    7. /*namespace Ui {
    8.   class Canicas;
    9. }*/
    10.  
    11. class Canicas : public QMainWindow
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. explicit Canicas(QWidget *parent = 0);
    17. ~Canicas();
    18.  
    19. private:
    20. Ui::CanicasClass ui;
    21.  
    22. void setConnections();
    23. };
    24.  
    25. #endif // CANICAS_H
    To copy to clipboard, switch view to plain text mode 


    .cpp
    Qt Code:
    1. #include "canicas.h"
    2. #include "ui_canicas.h"
    3. #include <QPushButton>
    4.  
    5. Canicas::Canicas(QWidget *parent) :
    6. QMainWindow(parent)
    7. {
    8. ui.setupUi(this);
    9.  
    10. setConnections();
    11. }
    12.  
    13. Canicas::~Canicas()
    14. {
    15. }
    16.  
    17. void Canicas::setConnections()
    18. {
    19. //ui.m_btnLevel1->scroll(0, 0); //Don't display an error
    20. connect(ui.m_btnLvl1, SIGNAL(clicked()),
    21. this, SLOT(level1()));
    22. /*QObject::connect(ui.m_btnLvl2, SIGNAL(clicked()),
    23.   this, SLOT(level2()));*/
    24. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2010
    Location
    Brazil
    Posts
    39
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem accesing to the widgets inside a UI.

    Did you try remove the explicit keyword at header file?

    And I think this part:

    Qt Code:
    1. private:
    2. Ui::CanicasClass ui;
    To copy to clipboard, switch view to plain text mode 

    Would be:
    Qt Code:
    1. private:
    2. Ui::Canicas ui;
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Problem accesing to the widgets inside a UI.

    You try to access via
    Qt Code:
    1. ui.m_btnLvl1
    To copy to clipboard, switch view to plain text mode 
    so there must be a button called "m_btnLvl1", but in the ui file you name it "m_btnLevel1". That's the point.

Similar Threads

  1. Drawing widgets inside a Qt application
    By aughey in forum Qt Programming
    Replies: 4
    Last Post: 13th May 2010, 08:45
  2. Problem accesing widgets
    By Greender in forum Qt Programming
    Replies: 4
    Last Post: 6th February 2009, 12:14
  3. Accesing widgets from separate thread
    By msmihai in forum Qt Programming
    Replies: 2
    Last Post: 8th December 2008, 11:48
  4. Widgets inside ListWidget ?
    By drake1983 in forum Newbie
    Replies: 1
    Last Post: 18th April 2008, 16:45
  5. QT 4.2.3 Using GTK Widgets inside QT App
    By chuckshaw in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2007, 03:40

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.