Results 1 to 5 of 5

Thread: how to link 1st screen to next screen ?

  1. #1
    Join Date
    Jan 2012
    Posts
    1
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default how to link 1st screen to next screen ?

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

    2. mainwindow.cpp (This is mainwindow.cpp file where i am connecting my 1st & 2nd button in textbox and in that window only the message is displaying)
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5.  
    6. QMainWindow(parent),
    7.  
    8. ui(new Ui::MainWindow)
    9.  
    10. {
    11. ui->setupUi(this);
    12.  
    13. connect(ui->CarInternals,SIGNAL(clicked()),this,SLOT(CarInternals_Clicked()));
    14. connect(ui->TellTales,SIGNAL(clicked()),this,SLOT(TellTales_Clicked()));
    15.  
    16. // connect(ui->CarInternals, SIGNAL(clicked()), setFocus, SLOT(setFocus()));
    17.  
    18. }
    19.  
    20. MainWindow::~MainWindow()
    21.  
    22. {
    23. delete ui;
    24. }
    To copy to clipboard, switch view to plain text mode 

    3. mainwindow.h (This is my header file)
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. namespace Ui {
    7.  
    8. class MainWindow;
    9. }
    10.  
    11. class MainWindow : public QMainWindow
    12.  
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. explicit MainWindow(QWidget *parent = 0);
    18.  
    19. ~MainWindow();
    20.  
    21.  
    22. private slots:
    23. void CarInternals_Clicked();
    24. void TellTales_Clicked();
    25. // void setFocus();
    26.  
    27. private:
    28.  
    29. Ui::MainWindow *ui;
    30.  
    31. };
    32.  
    33. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void MainWindow::CarInternals_Clicked()
    2. {
    3. ui->Message->setText( "Car Internals Button clicked ..." );
    4.  
    5. }
    6.  
    7. void MainWindow::TellTales_Clicked()
    8. {
    9. ui->Message->setText( "Tell Tales Button clicked ..." );
    10. }
    11.  
    12. /*void MainWindow::setFocus(), SLOT(screen2.ui)
    13. {
    14.  
    15. } */
    To copy to clipboard, switch view to plain text mode 

    4. mainwindow.ui (this is my 1st UI file.)
    xml Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>MainWindow</class>
    4. <widget class="QMainWindow" name="MainWindow">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>400</width>
    10. <height>300</height>
    11. </rect>
    12. </property>
    13. <property name="windowTitle">
    14. <string>MainWindow</string>
    15. </property>
    16. <widget class="QWidget" name="centralWidget">
    17. <widget class="QPushButton" name="CarInternals">
    18. <property name="geometry">
    19. <rect>
    20. <x>50</x>
    21. <y>20</y>
    22. <width>121</width>
    23. <height>27</height>
    24. </rect>
    25. </property>
    26. <property name="text">
    27. <string>Car Internals</string>
    28. </property>
    29. </widget>
    30. <widget class="QPushButton" name="TellTales">
    31. <property name="geometry">
    32. <rect>
    33. <x>220</x>
    34. <y>20</y>
    35. <width>121</width>
    36. <height>27</height>
    37. </rect>
    38. </property>
    39. <property name="text">
    40. <string>Tell Tales</string>
    41. </property>
    42. </widget>
    43. <widget class="QPushButton" name="AudioSystems">
    44. <property name="geometry">
    45. <rect>
    46. <x>50</x>
    47. <y>70</y>
    48. <width>121</width>
    49. <height>27</height>
    50. </rect>
    51. </property>
    52. <property name="text">
    53. <string>Audio System</string>
    54. </property>
    55. </widget>
    56. <widget class="QPushButton" name="WeeklyChecks">
    57. <property name="geometry">
    58. <rect>
    59. <x>220</x>
    60. <y>70</y>
    61. <width>121</width>
    62. <height>27</height>
    63. </rect>
    64. </property>
    65. <property name="text">
    66. <string>Weekly Checks</string>
    67. </property>
    68. </widget>
    69. <widget class="QPushButton" name="AirConditioner">
    70. <property name="geometry">
    71. <rect>
    72. <x>50</x>
    73. <y>120</y>
    74. <width>121</width>
    75. <height>27</height>
    76. </rect>
    77. </property>
    78. <property name="text">
    79. <string>Air Conditioner</string>
    80. </property>
    81. </widget>
    82. <widget class="QPushButton" name="TeoubleShooting">
    83. <property name="geometry">
    84. <rect>
    85. <x>220</x>
    86. <y>120</y>
    87. <width>121</width>
    88. <height>27</height>
    89. </rect>
    90. </property>
    91. <property name="text">
    92. <string>Trouble Shooting</string>
    93. </property>
    94. </widget>
    95. <widget class="QPushButton" name="EHub">
    96. <property name="geometry">
    97. <rect>
    98. <x>50</x>
    99. <y>170</y>
    100. <width>121</width>
    101. <height>27</height>
    102. </rect>
    103. </property>
    104. <property name="text">
    105. <string>E-Hub</string>
    106. </property>
    107. </widget>
    108. <widget class="QPushButton" name="Back">
    109. <property name="geometry">
    110. <rect>
    111. <x>220</x>
    112. <y>170</y>
    113. <width>121</width>
    114. <height>27</height>
    115. </rect>
    116. </property>
    117. <property name="text">
    118. <string>Back</string>
    119. </property>
    120. </widget>
    121. <widget class="QTextEdit" name="Message">
    122. <property name="geometry">
    123. <rect>
    124. <x>70</x>
    125. <y>220</y>
    126. <width>291</width>
    127. <height>89</height>
    128. </rect>
    129. </property>
    130. </widget>
    131. </widget>
    132. </widget>
    133. <layoutdefault spacing="6" margin="11"/>
    134. <resources/>
    135. <connections/>
    136. </ui>
    To copy to clipboard, switch view to plain text mode 


    5. screen2.ui (This is my 2nd UI file)
    I want to connect my 1st UI Screen when i click on "Car Internals" it shud go the screen2 and display the list view.
    The following is my 2nd screen2.ui code
    xml Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>Form</class>
    4. <widget class="QWidget" name="Form">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>400</width>
    10. <height>370</height>
    11. </rect>
    12. </property>
    13. <property name="windowTitle">
    14. <string>Form</string>
    15. </property>
    16. <widget class="QPushButton" name="pushButton">
    17. <property name="geometry">
    18. <rect>
    19. <x>50</x>
    20. <y>20</y>
    21. <width>331</width>
    22. <height>27</height>
    23. </rect>
    24. </property>
    25. <property name="text">
    26. <string>Car Internals Contain the Following List</string>
    27. </property>
    28. </widget>
    29. <widget class="QListView" name="listView">
    30. <property name="geometry">
    31. <rect>
    32. <x>70</x>
    33. <y>60</y>
    34. <width>256</width>
    35. <height>251</height>
    36. </rect>
    37. </property>
    38. </widget>
    39. <widget class="QCommandLinkButton" name="commandLinkButton">
    40. <property name="geometry">
    41. <rect>
    42. <x>90</x>
    43. <y>90</y>
    44. <width>178</width>
    45. <height>41</height>
    46. </rect>
    47. </property>
    48. <property name="text">
    49. <string>Seat</string>
    50. </property>
    51. </widget>
    52. <widget class="QCommandLinkButton" name="commandLinkButton_2">
    53. <property name="geometry">
    54. <rect>
    55. <x>90</x>
    56. <y>120</y>
    57. <width>178</width>
    58. <height>41</height>
    59. </rect>
    60. </property>
    61. <property name="text">
    62. <string>Seat Belt</string>
    63. </property>
    64. </widget>
    65. <widget class="QCommandLinkButton" name="commandLinkButton_3">
    66. <property name="geometry">
    67. <rect>
    68. <x>90</x>
    69. <y>150</y>
    70. <width>178</width>
    71. <height>41</height>
    72. </rect>
    73. </property>
    74. <property name="text">
    75. <string>Air Bags</string>
    76. </property>
    77. </widget>
    78. <widget class="QCommandLinkButton" name="commandLinkButton_4">
    79. <property name="geometry">
    80. <rect>
    81. <x>90</x>
    82. <y>180</y>
    83. <width>178</width>
    84. <height>41</height>
    85. </rect>
    86. </property>
    87. <property name="text">
    88. <string>Mirrors</string>
    89. </property>
    90. </widget>
    91. <widget class="QCommandLinkButton" name="commandLinkButton_5">
    92. <property name="geometry">
    93. <rect>
    94. <x>90</x>
    95. <y>210</y>
    96. <width>178</width>
    97. <height>41</height>
    98. </rect>
    99. </property>
    100. <property name="text">
    101. <string>Storage Compartment</string>
    102. </property>
    103. </widget>
    104. <widget class="QCommandLinkButton" name="commandLinkButton_6">
    105. <property name="geometry">
    106. <rect>
    107. <x>90</x>
    108. <y>240</y>
    109. <width>178</width>
    110. <height>41</height>
    111. </rect>
    112. </property>
    113. <property name="text">
    114. <string>Back</string>
    115. </property>
    116. </widget>
    117. </widget>
    118. <resources/>
    119. <connections/>
    120. </ui>
    To copy to clipboard, switch view to plain text mode 


    these are the 5 files where i have written the code. I want to connect my 1st UI screen which consists of the button "Car Internals" When i click on the "Car Internals button it shud go the next screen. i.e., screen2. Similarly I want to do foe all the buttons which i have shown in the mainwindow.ui file.

    Please help...

    Thank You Sir/Ma'am.
    Last edited by wysota; 24th January 2012 at 10:50. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to link 1st screen to next screen ?

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2011
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to link 1st screen to next screen ?

    Hi i suggest you place your widget inside a stackedwidget , a stackedwidget consist of yr 5 pages. After which just set ui->stackedwidget->setCurrentIndex(---yr page number).

  4. #4
    Join Date
    Jan 2012
    Posts
    15
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: how to link 1st screen to next screen ?

    You can do this:

    On the currentwindow.h
    #include windowtopen.h

    public slots:
    void openwindowtoopen(); // Create a void function to open the window

    private slots:
    ClasstoOpen * windowVar; //Make a variable for the window to open

    private slots:
    void on_buttontoclick_clicked(); //Standar method, use the name of the button



    ......



    Then go to currentwindow.cpp and using all the names u put in the .h file

    add this :

    void CurrentClass:: on_buttontoclick_clicked(){
    openwindowtoopen();
    }

    void CurrentClass:: openwindowtoopen(){
    close(); //This will close the current window, you can delete it if u want to keep it opened
    windowVar = new ClasstoOpen (this);
    windowVar->show(); -> This will show the new window
    }



    Now you will get ur window opened... if u closed the previous window, and then u want to call it back, you can do this:

    on the windowuopened.h

    private slots:

    void on_buttontoopenclosedwindow_clicked();

    ..........

    on the windowuopened.cpp

    #include windowyouclosed.h

    void ClassyouOpened:: on_buttontoopenclosedwindow_clicked(){

    ClassyouClosed * windowYouClosed; //Declare a variable for the previous window

    close(); //Closes the current window
    windowYouClosed = new ClassYouClosed (this);
    windowYouClosed->show(); //Shows the previous window

    }

  5. #5
    Join Date
    Feb 2012
    Posts
    27
    Thanked 2 Times in 2 Posts

    Default Re: how to link 1st screen to next screen ?

    USe Stackwidget in .ui file of your project it will become very easy to you for understanding....

Similar Threads

  1. go next screen
    By sabbu in forum Newbie
    Replies: 5
    Last Post: 6th May 2011, 08:09
  2. Replies: 3
    Last Post: 25th January 2011, 13:36
  3. Replies: 0
    Last Post: 19th January 2011, 03:29
  4. application screen as screen saver
    By wizarda in forum Qt Programming
    Replies: 0
    Last Post: 6th January 2011, 19:15
  5. Replies: 2
    Last Post: 11th June 2010, 07:23

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