Results 1 to 4 of 4

Thread: Passing Ui files as parameter

  1. #1
    Join Date
    Jul 2007
    Posts
    104
    Thanks
    22
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Passing Ui files as parameter

    I have two Ui objects in my class header.I know that the Ui classes dont inherit form QObject.But I want to pass these objects to a function.Dynamically It will work.Question:Is there a way of passing these two different class objects?(Ex:QPushButton and QLabel.... can be passed as QWidget...)

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Passing Ui files as parameter

    Different Ui classes have nothing in common. But for them to be usable, you'll need to load them to a widget anyway. So basically you could load them to corresponding widgets and pass them to your function. But may I ask, what do you actually intend to do? Could you describe what's the purpose of the function?
    J-P Nurmi

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Passing Ui files as parameter

    you might want to have a look at QUiLoader, maybe it will help you achieve what you want.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. #4
    Join Date
    Jul 2007
    Posts
    104
    Thanks
    22
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Passing Ui files as parameter

    I have a form and a dialog.Both of them has same widgets(LineEdits,Labels...).Reading Id's from XML I am showing informations of objects on form and dialog.But If user wants to change values of objects he will use dialog.So I have two UI objects.Form and dialog objects .And they have same functions...If I could pass UI objects dynamically I can write some functions once.
    Qt Code:
    1. void ProgramEditor::CreateEditorPointMenu()
    2. {
    3. int countOfCom,countOfLabel;
    4. QString InputWidget;
    5.  
    6. CommandList.clear();
    7. Data::ReadTypeList(commandNumber,CommandList);
    8. InputWidget=CommandList[0];
    9. countOfCom=InputWidget.count("1");
    10. countOfLabel=0;
    11. openWidgets.clear();
    12.  
    13. switch(countOfCom)
    14. {
    15. case 4:
    16. countOfLabel=4;
    17. SetPointMenuArrange(countOfLabel,UIeditor->label_4,UIeditor->lineEdit_4);
    18. case 3:
    19. if(countOfLabel==0)
    20. countOfLabel=3;
    21. SetPointMenuArrange(countOfLabel,UIeditor->label_3,UIeditor->lineEdit_3);
    22. case 2:
    23. if(countOfLabel==0)
    24. countOfLabel=2;
    25. SetPointMenuArrange(countOfLabel,UIeditor->label_2,UIeditor->lineEdit_2);
    26. case 1:
    27. if(countOfLabel==0)
    28. countOfLabel=1;
    29. SetPointMenuArrange(countOfLabel,UIeditor->label_1,UIeditor->lineEdit_1);
    30. break;
    31. default:
    32. break;
    33. }
    34. countOfCom=0;
    35. countOfCom=InputWidget.count("2");
    36. switch(countOfCom)
    37. {
    38. case 2:
    39. SetPointMenuItems(UIeditor->label_6,UIeditor->comboBox_2,CommandList[countOfLabel+2]);
    40.  
    41. case 1:
    42. SetPointMenuItems(UIeditor->label_5,UIeditor->comboBox_1,CommandList[countOfLabel+1]);
    43. break;
    44.  
    45. default:
    46. break;
    47. }
    48. countOfCom=0;
    49. countOfCom=InputWidget.count("3");
    50. switch(countOfCom)
    51. {
    52. case 2:
    53. if(UIeditor->checkBox_2->isVisible()==false)
    54. {
    55. UIeditor->checkBox_2->setVisible(true);
    56. openWidgets.push_back(UIeditor->checkBox_2);
    57. }
    58. case 1:
    59. if(UIeditor->checkBox_1->isVisible()==false)
    60. {
    61. UIeditor->checkBox_1->setVisible(true);
    62. openWidgets.push_back(UIeditor->checkBox_1);
    63. }
    64. break;
    65. default:
    66. break;
    67. }
    68.  
    69. }
    70.  
    71. void ProgramEditor::CreateSetPointEditor()
    72. {
    73. int countOfCom,countOfLabel;
    74. QString InputWidget;
    75.  
    76. CommandList.clear();
    77. Data::ReadTypeList(commandNumber,CommandList);
    78. InputWidget=CommandList[0];
    79. countOfCom=InputWidget.count("1");
    80. countOfLabel=0;
    81. openWidgets.clear();
    82.  
    83. switch(countOfCom)
    84. {
    85. case 4:
    86. countOfLabel=4;
    87. SetPointMenuArrange(countOfLabel,UIsetPoint->label_4,UIsetPoint->lineEdit_4,
    88. UIeditor->lineEdit_4,true);
    89. case 3:
    90. if(countOfLabel==0)
    91. countOfLabel=3;
    92. SetPointMenuArrange(countOfLabel,UIsetPoint->label_3,UIsetPoint->lineEdit_3,
    93. UIeditor->lineEdit_3,true);
    94. case 2:
    95. if(countOfLabel==0)
    96. countOfLabel=2;
    97. SetPointMenuArrange(countOfLabel,UIsetPoint->label_2,UIsetPoint->lineEdit_2,
    98. UIeditor->lineEdit_2,true);
    99. case 1:
    100. if(countOfLabel==0)
    101. countOfLabel=1;
    102. SetPointMenuArrange(countOfLabel,UIsetPoint->label_1,UIsetPoint->lineEdit_1,
    103. UIeditor->lineEdit_1,true);
    104. break;
    105. default:
    106. break;
    107. }
    108. countOfCom=0;
    109. countOfCom=InputWidget.count("2");
    110. switch(countOfCom)
    111. {
    112. case 2:
    113. SetPointMenuItems(UIsetPoint->label_6,UIsetPoint->comboBox_2,CommandList[countOfLabel+2]);
    114. case 1:
    115. SetPointMenuItems(UIsetPoint->label_5,UIsetPoint->comboBox_1,CommandList[countOfLabel+1]);
    116. break;
    117.  
    118. default:
    119. break;
    120. }
    121. countOfCom=0;
    122. countOfCom=InputWidget.count("3");
    123. switch(countOfCom)
    124. {
    125. case 2:
    126. if(UIsetPoint->checkBox_2->isVisible()==false)
    127. {
    128. UIsetPoint->checkBox_2->setVisible(true);
    129. openWidgets.push_back(UIsetPoint->checkBox_2);
    130. }
    131. case 1:
    132. if(UIsetPoint->checkBox_1->isVisible()==false)
    133. {
    134. UIsetPoint->checkBox_1->setVisible(true);
    135. openWidgets.push_back(UIsetPoint->checkBox_1);
    136. }
    137. break;
    138. default:
    139. break;
    140. }
    141. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 12th December 2007 at 12:19. Reason: missing [code] tags

Similar Threads

  1. Passing QFile objecrt as parameter
    By db in forum Newbie
    Replies: 2
    Last Post: 28th August 2007, 16:09
  2. Replies: 5
    Last Post: 22nd September 2006, 08:04
  3. [Win32/VC++ 8.0] Strange problems with qrc_*.cpp files
    By mloskot in forum Installation and Deployment
    Replies: 6
    Last Post: 6th March 2006, 10:28

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
  •  
Qt is a trademark of The Qt Company.