PDA

View Full Version : how to link 1st screen to next screen ?



Nanda
24th January 2012, 04:52
This is my code...
1. main.cpp

#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();

return a.exec();
}


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)

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :

QMainWindow(parent),

ui(new Ui::MainWindow)

{
ui->setupUi(this);

connect(ui->CarInternals,SIGNAL(clicked()),this,SLOT(CarIntern als_Clicked()));
connect(ui->TellTales,SIGNAL(clicked()),this,SLOT(TellTales_Cl icked()));

// connect(ui->CarInternals, SIGNAL(clicked()), setFocus, SLOT(setFocus()));

}

MainWindow::~MainWindow()

{
delete ui;
}

3. mainwindow.h (This is my header file)

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {

class MainWindow;
}

class MainWindow : public QMainWindow

{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);

~MainWindow();


private slots:
void CarInternals_Clicked();
void TellTales_Clicked();
// void setFocus();

private:

Ui::MainWindow *ui;

};

#endif // MAINWINDOW_H


void MainWindow::CarInternals_Clicked()
{
ui->Message->setText( "Car Internals Button clicked ..." );

}

void MainWindow::TellTales_Clicked()
{
ui->Message->setText( "Tell Tales Button clicked ..." );
}

/*void MainWindow::setFocus(), SLOT(screen2.ui)
{

} */

4. mainwindow.ui (this is my 1st UI file.)
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QPushButton" name="CarInternals">
<property name="geometry">
<rect>
<x>50</x>
<y>20</y>
<width>121</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Car Internals</string>
</property>
</widget>
<widget class="QPushButton" name="TellTales">
<property name="geometry">
<rect>
<x>220</x>
<y>20</y>
<width>121</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Tell Tales</string>
</property>
</widget>
<widget class="QPushButton" name="AudioSystems">
<property name="geometry">
<rect>
<x>50</x>
<y>70</y>
<width>121</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Audio System</string>
</property>
</widget>
<widget class="QPushButton" name="WeeklyChecks">
<property name="geometry">
<rect>
<x>220</x>
<y>70</y>
<width>121</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Weekly Checks</string>
</property>
</widget>
<widget class="QPushButton" name="AirConditioner">
<property name="geometry">
<rect>
<x>50</x>
<y>120</y>
<width>121</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Air Conditioner</string>
</property>
</widget>
<widget class="QPushButton" name="TeoubleShooting">
<property name="geometry">
<rect>
<x>220</x>
<y>120</y>
<width>121</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Trouble Shooting</string>
</property>
</widget>
<widget class="QPushButton" name="EHub">
<property name="geometry">
<rect>
<x>50</x>
<y>170</y>
<width>121</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>E-Hub</string>
</property>
</widget>
<widget class="QPushButton" name="Back">
<property name="geometry">
<rect>
<x>220</x>
<y>170</y>
<width>121</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Back</string>
</property>
</widget>
<widget class="QTextEdit" name="Message">
<property name="geometry">
<rect>
<x>70</x>
<y>220</y>
<width>291</width>
<height>89</height>
</rect>
</property>
</widget>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>


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 version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>370</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>50</x>
<y>20</y>
<width>331</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Car Internals Contain the Following List</string>
</property>
</widget>
<widget class="QListView" name="listView">
<property name="geometry">
<rect>
<x>70</x>
<y>60</y>
<width>256</width>
<height>251</height>
</rect>
</property>
</widget>
<widget class="QCommandLinkButton" name="commandLinkButton">
<property name="geometry">
<rect>
<x>90</x>
<y>90</y>
<width>178</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Seat</string>
</property>
</widget>
<widget class="QCommandLinkButton" name="commandLinkButton_2">
<property name="geometry">
<rect>
<x>90</x>
<y>120</y>
<width>178</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Seat Belt</string>
</property>
</widget>
<widget class="QCommandLinkButton" name="commandLinkButton_3">
<property name="geometry">
<rect>
<x>90</x>
<y>150</y>
<width>178</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Air Bags</string>
</property>
</widget>
<widget class="QCommandLinkButton" name="commandLinkButton_4">
<property name="geometry">
<rect>
<x>90</x>
<y>180</y>
<width>178</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Mirrors</string>
</property>
</widget>
<widget class="QCommandLinkButton" name="commandLinkButton_5">
<property name="geometry">
<rect>
<x>90</x>
<y>210</y>
<width>178</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Storage Compartment</string>
</property>
</widget>
<widget class="QCommandLinkButton" name="commandLinkButton_6">
<property name="geometry">
<rect>
<x>90</x>
<y>240</y>
<width>178</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Back</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>


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.

wysota
24th January 2012, 10:50
http://www.qtcentre.org/faq.php?faq=qt_general_category#faq_qt_designer_2f orms

seanasl
24th January 2012, 14:46
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). :)

danoc93
24th January 2012, 17:28
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

}

RENOLD
17th February 2012, 11:30
USe Stackwidget in .ui file of your project it will become very easy to you for understanding....