Results 1 to 2 of 2

Thread: initial comboboxes at Qt using Ui

  1. #1
    Join Date
    Nov 2013
    Posts
    15
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default initial comboboxes at Qt using Ui

    I am new at Qt. I searched for some hours now but I'm not able to find a solution.

    My setup is as follows:


    main.cpp
    projectQt.cpp
    projectQt.h
    tab1.h
    tab1.cpp
    tab2.h
    tab2.cpp
    projectQt.ui



    I want to create a project with Ui file. At the Ui file, i have three comboBox and two Apply button and at the tab1.cpp and tab2.cpp, I want to add initial Items of the comboboxes. If the user click the apply buttons, run the "OnBtnApplyClicked" methods. I have error of the project. please help me.

    main.cpp



    Qt Code:
    1. #include "projectQt.h"
    2.  
    3. #include <QtWidgets/QApplication>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8. ProjectQt w;
    9. w.show();
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 




    projectQt.ui file:



    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>ProjectQtClass</class>
    4. <widget class="QMainWindow" name="ProjectQtClass">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>900</width>
    10. <height>900</height>
    11. </rect>
    12. </property>
    13. <property name="windowTitle">
    14. <string>ProjectQt</string>
    15. </property>
    16. <widget class="QWidget" name="centralWidget">
    17. <widget class="QTabWidget" name="tabWidget">
    18. <property name="geometry">
    19. <rect>
    20. <x>10</x>
    21. <y>40</y>
    22. <width>800</width>
    23. <height>800</height>
    24. </rect>
    25. </property>
    26. <property name="currentIndex">
    27. <number>1</number>
    28. </property>
    29. <widget class="QWidget" name="IDC_FORM_TAB_1">
    30. <attribute name="title">
    31. <string>M001</string>
    32. </attribute>
    33. <widget class="QLabel" name="IDC_LBL_1_0">
    34. <property name="geometry">
    35. <rect>
    36. <x>10</x>
    37. <y>40</y>
    38. <width>124</width>
    39. <height>13</height>
    40. </rect>
    41. </property>
    42. <property name="text">
    43. <string>COMBO1</string>
    44. </property>
    45. </widget>
    46. <widget class="QComboBox" name="IDC_CMB_1_0">
    47. <property name="geometry">
    48. <rect>
    49. <x>120</x>
    50. <y>40</y>
    51. <width>69</width>
    52. <height>22</height>
    53. </rect>
    54. </property>
    55. </widget>
    56. <widget class="QComboBox" name="IDC_CMB_1_1">
    57. <property name="geometry">
    58. <rect>
    59. <x>120</x>
    60. <y>90</y>
    61. <width>69</width>
    62. <height>22</height>
    63. </rect>
    64. </property>
    65. </widget>
    66. <widget class="QPushButton" name="IDC_BTN_1_Apply">
    67. <property name="geometry">
    68. <rect>
    69. <x>180</x>
    70. <y>174</y>
    71. <width>75</width>
    72. <height>23</height>
    73. </rect>
    74. </property>
    75. <property name="text">
    76. <string>Apply</string>
    77. </property>
    78. </widget>
    79. <widget class="QLabel" name="IDC_LBL_1_1">
    80. <property name="geometry">
    81. <rect>
    82. <x>10</x>
    83. <y>90</y>
    84. <width>124</width>
    85. <height>13</height>
    86. </rect>
    87. </property>
    88. <property name="text">
    89. <string>COMBO2</string>
    90. </property>
    91. </widget>
    92. </widget>
    93. <widget class="QWidget" name="IDC_FORM_TAB_2">
    94. <attribute name="title">
    95. <string>M002</string>
    96. </attribute>
    97. <widget class="QLabel" name="IDC_LBL_2_0">
    98. <property name="geometry">
    99. <rect>
    100. <x>0</x>
    101. <y>30</y>
    102. <width>104</width>
    103. <height>13</height>
    104. </rect>
    105. </property>
    106. <property name="text">
    107. <string>COMBO3</string>
    108. </property>
    109. </widget>
    110. <widget class="QComboBox" name="IDC_CMB_2_0">
    111. <property name="geometry">
    112. <rect>
    113. <x>100</x>
    114. <y>30</y>
    115. <width>69</width>
    116. <height>22</height>
    117. </rect>
    118. </property>
    119. </widget>
    120. <widget class="QPushButton" name="IDC_BTN_2_Apply">
    121. <property name="geometry">
    122. <rect>
    123. <x>100</x>
    124. <y>70</y>
    125. <width>75</width>
    126. <height>23</height>
    127. </rect>
    128. </property>
    129. <property name="text">
    130. <string>Apply</string>
    131. </property>
    132. </widget>
    133. </widget>
    134. </widget>
    135. </widget>
    136. <widget class="QMenuBar" name="menuBar">
    137. <property name="geometry">
    138. <rect>
    139. <x>0</x>
    140. <y>0</y>
    141. <width>900</width>
    142. <height>21</height>
    143. </rect>
    144. </property>
    145. </widget>
    146. <widget class="QToolBar" name="mainToolBar">
    147. <attribute name="toolBarArea">
    148. <enum>TopToolBarArea</enum>
    149. </attribute>
    150. <attribute name="toolBarBreak">
    151. <bool>false</bool>
    152. </attribute>
    153. </widget>
    154. <widget class="QStatusBar" name="statusBar"/>
    155. </widget>
    156. <layoutdefault spacing="6" margin="11"/>
    157. <resources>
    158. <include location="projectQt.qrc"/>
    159. </resources>
    160. <connections/>
    161. </ui>
    To copy to clipboard, switch view to plain text mode 


    projectQt.cpp file:


    Qt Code:
    1. #include "projectQt.h"
    2. #include "tab1.h"
    3. #include "tab2.h"
    4. #include "ui_projectQt.h"
    5. Ctab1 *ctab1=new Ctab1;
    6. Ctab2 *ctab2=new Ctab2;
    7. ProjectQt::ProjectQt(QWidget *parent)
    8. : QMainWindow(parent),
    9. ui(new Ui::ProjectQtClass)
    10. {
    11. ui->setupUi(this);
    12.  
    13. ctab1->initGUI();
    14. ctab2->initGUI();
    15. ui->IDC_CMB_2_0->addItem("123");
    16.  
    17. connect(ui->IDC_BTN_1_Apply,SIGNAL(clicked()),this,SLOT(Ctab1::OnBtnApplyClicked()));
    18. connect(ui->IDC_BTN_2_Apply,SIGNAL(clicked()),this,SLOT(Ctab2::OnBtnApplyClicked()));
    19. }
    20. ProjectQt::~ProjectQt()
    21. {
    22. }
    To copy to clipboard, switch view to plain text mode 


    projectQt.h file:




    Qt Code:
    1. #ifndef projectQt_H
    2. #define projectQt_H
    3.  
    4. #include <QtWidgets/QMainWindow>
    5. #include "ui_projectQt.h"
    6. #include "tab1.h"
    7. #include "tab2.h"
    8.  
    9. class ProjectQt : public QMainWindow
    10.  
    11. {
    12.  
    13. Q_OBJECT
    14.  
    15. public:
    16.  
    17. ProjectQt(QWidget *parent = 0);
    18. ~ProjectQt();
    19.  
    20. Ui::ProjectQtClass *ui;
    21.  
    22. };
    23.  
    24. #endif // projectQt_H
    To copy to clipboard, switch view to plain text mode 





    tab1.h file:

    Qt Code:
    1. #pragma once
    2. #include <string>
    3. #include "projectQt.h"
    4. #include "ui_projectQt.h"
    5. class Ctab1
    6. {
    7.  
    8. public:
    9. Ctab1(void);
    10. ~Ctab1(void);
    11.  
    12. public slots:
    13.  
    14. void setEvents();
    15. void initGUI();
    16. void OnBtnApplyClicked();
    17.  
    18. };
    To copy to clipboard, switch view to plain text mode 

    tab1.cpp file:




    Qt Code:
    1. #include "projectQt.h"
    2. #include "tab1.h"
    3. #include <QTextStream>
    4. #include "ui_projectQt.h"
    5.  
    6. Ctab1::Ctab1(void)
    7. {
    8.  
    9. }
    10.  
    11. Ctab1::~Ctab1()
    12.  
    13. {
    14.  
    15. }
    16.  
    17. void Ctab1::initGUI(){
    18.  
    19. ui->IDC_CMB_1_1->addItem("adsa");
    20.  
    21. }
    22.  
    23.  
    24. void Ctab1::OnBtnApplyClicked(){
    25.  
    26. }
    To copy to clipboard, switch view to plain text mode 

     

     





    tab2.h file:


    Qt Code:
    1. #pragma once
    2. #include <string>
    3. #include "projectQt.h"
    4. #include "ui_projectQt.h"
    5. class Ctab2
    6. {
    7.  
    8. public:
    9. Ctab1(void);
    10. ~Ctab1(void);
    11.  
    12. public slots:
    13.  
    14. void setEvents();
    15. void initGUI();
    16. void OnBtnApplyClicked();
    17.  
    18. };
    To copy to clipboard, switch view to plain text mode 

    tab2.cpp file:


    Qt Code:
    1. #include "projectQt.h"
    2. #include "tab2.h"
    3. #include <QTextStream>
    4. #include "ui_projectQt.h"
    5.  
    6. Ctab2::Ctab2(void)
    7. {
    8.  
    9. }
    10.  
    11. Ctab2::~Ctab2()
    12.  
    13. {
    14.  
    15. }
    16.  
    17. void Ctab2::initGUI(){
    18.  
    19. ui->IDC_CMB_2_0->addItem("adsaxxx");
    20.  
    21. }
    22.  
    23.  
    24. void Ctab2::OnBtnApplyClicked(){
    25.  
    26. }
    To copy to clipboard, switch view to plain text mode 

     



    I cant declare ui identifier for Tab1 and Tab2. How can i declare it for Tab1.cpp and Tab2.cpp files. If i declare ui, I will solve the problem (I hope ).
    Last edited by citix; 24th November 2013 at 13:30.

  2. #2
    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: initial comboboxes at Qt using Ui

    Your connect() lines look wrong.
    The SLOT() macro takes only the slot name and its argument types, not a class prefix. And the receiver object should probably not be "this" but the respective tab object, no?

    Cheers,
    _

Similar Threads

  1. Populating, signals and comboboxes
    By ShamusVW in forum Newbie
    Replies: 6
    Last Post: 12th August 2010, 06:43
  2. Mapping between two comboboxes
    By codeman in forum Qt Programming
    Replies: 1
    Last Post: 28th December 2009, 17:32
  3. Replies: 2
    Last Post: 11th August 2009, 16:01
  4. size comboboxes
    By mattia in forum Newbie
    Replies: 2
    Last Post: 14th November 2007, 14:55
  5. comboboxes get stuck
    By illuzioner in forum Qt Programming
    Replies: 2
    Last Post: 30th March 2006, 01:03

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.