I am creating an application in which i want a functionality in which whenever a radio button is checked,the content appearing in a tab must be changed.but the problem is when i connect the button with the tab,nothing happens.I am creating an object of a class which creates the tab firstly, within the slot to change the content of the tab whenever it will be checked. But this is not working as the content of tab is not changing.
Can any one help with this problem?
I am attaching the code of my program as well.
Header file:
Qt Code:
  1. #ifndef V_LAB_H
  2. #define V_LAB_H
  3. #include<QDialog>
  4. #include<QVBoxLayout>
  5. #include<QHBoxLayout>
  6. #include<QGroupBox>
  7. #include<QRadioButton>
  8. #include<QPalette>
  9. #include<QSize>
  10. #include<QTabWidget>
  11. #include<QLabel>
  12. class QGroupBox;
  13. class QPalette;
  14. class QSize;
  15.  
  16. class QTabWidget;
  17.  
  18. /*class psudo_code:public QWidget
  19. {
  20.   Q_OBJECT
  21.   public:
  22.   psudo_code(QWidget *parent = 0);
  23. private:
  24.   QLabel *label1;
  25.   QVBoxLayout *main_layout1;
  26. };*/
  27.  
  28. class v_lab:public QDialog
  29. {
  30. Q_OBJECT
  31. public:
  32. v_lab(QWidget *parent = 0);
  33. signals:
  34.  
  35.  
  36.  
  37.  
  38. public slots:
  39. void peeyush();
  40.  
  41.  
  42. private:
  43.  
  44. QGroupBox *maingroup;
  45. QGroupBox *box;
  46. QHBoxLayout *mainlayout;
  47.  
  48. QVBoxLayout *main_left_pane_layout;
  49. QVBoxLayout *left_pane_box;
  50. QVBoxLayout *left_pane_box1;
  51. QVBoxLayout *left_pane_box2;
  52. QVBoxLayout *left_pane_box3;
  53. QGroupBox *box1;
  54.  
  55. QGroupBox *box2;
  56.  
  57. QGroupBox *box3;
  58.  
  59. QRadioButton *linear_search;
  60. QRadioButton *binary_search;
  61. QRadioButton *bubble_sort;
  62. QRadioButton *selection_sort;
  63. QRadioButton *infix_traversal;
  64. QRadioButton *prefix_traversal;
  65. QRadioButton *postfix_traversal;
  66. QRadioButton *shortest_path;
  67. QTabWidget *tab;
  68.  
  69.  
  70. QString string2;
  71. };
  72.  
  73.  
  74. class algorithm:public QWidget
  75. {
  76. Q_OBJECT
  77. public:
  78. algorithm(const QString &string,QWidget *parent = 0);
  79.  
  80.  
  81.  
  82. private:
  83. QLabel *label;
  84. QLabel *label1;
  85. QVBoxLayout *main_layout;
  86. QVBoxLayout *main_layout1;
  87. };
  88.  
  89. #endif // V_LAB_H
To copy to clipboard, switch view to plain text mode 
source file (v_lab.cpp)
Qt Code:
  1. #include<QtGui>
  2. #include "v_lab.h"
  3.  
  4. v_lab::v_lab(QWidget *parent)
  5. :QDialog(parent)
  6. {
  7.  
  8. setWindowTitle("Virtual Lab");
  9. maingroup=new QGroupBox(this);
  10. maingroup->setTitle("Algorithms");
  11. maingroup->setMinimumWidth(200);
  12. maingroup->setMaximumWidth(240);
  13. maingroup->setFlat(false);
  14. p=new QPalette;
  15. p->setColor(QPalette::Background,QColor(233,212,102));
  16. setPalette(*p);
  17.  
  18.  
  19. box=new QGroupBox(maingroup);
  20. box->setFlat(false);
  21. box->setTitle("Searching Algorithm");
  22.  
  23.  
  24.  
  25.  
  26. linear_search=new QRadioButton("Linear Search",box);
  27. linear_search->setChecked(1);
  28. binary_search=new QRadioButton("Binary Search",box);
  29.  
  30.  
  31. box1=new QGroupBox(maingroup);
  32. box1->setFlat(false);
  33. box1->setTitle("Sorting Algorithms");
  34.  
  35.  
  36. bubble_sort=new QRadioButton("Bubble Sort",box1);
  37. selection_sort=new QRadioButton("Selection Sort",box1);
  38.  
  39.  
  40. box2=new QGroupBox(maingroup);
  41. box2->setFlat(false);
  42. box2->setTitle("Tree Algorithms");
  43.  
  44.  
  45. infix_traversal=new QRadioButton("Infix Traversal",box2);
  46. prefix_traversal=new QRadioButton("Prefix Traversal",box2);
  47. postfix_traversal=new QRadioButton("Postfix Traversal",box2);
  48.  
  49.  
  50.  
  51. box3=new QGroupBox(maingroup);
  52. box3->setFlat(false);
  53. box3->setTitle("Graph Algorithms");
  54.  
  55.  
  56. bfs=new QRadioButton("BFS",box3);
  57.  
  58. dfs=new QRadioButton("DFS",box3);
  59. shortest_path=new QRadioButton("Shortest Path",box3);
  60.  
  61. QString string1="Start Tab";
  62. tab=new QTabWidget;
  63. tab->addTab(new algorithm(string1),"Algorithm");
  64. //tab->addTab(new psudo_code(),"Pseduo-Code");
  65. tab->setMinimumWidth(250);
  66. tab->setMaximumWidth(400);
  67.  
  68.  
  69.  
  70.  
  71. //Layout
  72. mainlayout=new QHBoxLayout(this);
  73. mainlayout->addWidget(maingroup);
  74.  
  75. mainlayout->addWidget(tab);
  76. mainlayout->addStretch();
  77. main_left_pane_layout=new QVBoxLayout(maingroup);
  78.  
  79. main_left_pane_layout->addWidget(box);
  80. main_left_pane_layout->addWidget(box1);
  81. main_left_pane_layout->addWidget(box2);
  82. main_left_pane_layout->addWidget(box3);
  83.  
  84. left_pane_box=new QVBoxLayout(box);
  85.  
  86. left_pane_box->addWidget(linear_search);
  87. left_pane_box->addWidget(binary_search);
  88.  
  89.  
  90. left_pane_box1=new QVBoxLayout(box1);
  91.  
  92. left_pane_box1->addWidget(bubble_sort);
  93. left_pane_box1->addWidget(selection_sort);
  94.  
  95. left_pane_box2=new QVBoxLayout(box2);
  96.  
  97. left_pane_box2->addWidget(infix_traversal);
  98. left_pane_box2->addWidget(prefix_traversal);
  99. left_pane_box2->addWidget(postfix_traversal);
  100.  
  101. left_pane_box3=new QVBoxLayout(box3);
  102.  
  103. left_pane_box3->addWidget(bfs);
  104. left_pane_box3->addWidget(dfs);
  105. left_pane_box3->addWidget(shortest_path);
  106.  
  107.  
  108. connect(binary_search,SIGNAL(clicked()),this,SLOT(peeyush()));
  109.  
  110. }
  111. algorithm::algorithm(const QString &string,QWidget *parent)
  112. :QWidget(parent)
  113. {
  114.  
  115. label=new QLabel(string);
  116. main_layout=new QVBoxLayout;
  117. main_layout->addWidget(label);
  118. main_layout->addStretch();
  119. setLayout(main_layout);
  120. }
  121.  
  122. void v_lab::peeyush()
  123. {
  124. string2="test 2";
  125. new algorithm(string2);
  126.  
  127. //exit(1);
  128. }
To copy to clipboard, switch view to plain text mode 
main.cpp
Qt Code:
  1. #include <QApplication>
  2. #include"v_lab.h"
  3. int main(int argc, char *argv[])
  4. {
  5. QApplication app(argc, argv);
  6. v_lab *dialog = new v_lab;
  7.  
  8.  
  9. dialog->show();
  10. return app.exec();
  11. }
To copy to clipboard, switch view to plain text mode