Switching between two ui forms / QMainWindow screens
-
Not to sound rude but that code base is a bit messy:
- You have two **Gui objects in you main.cpp that are not used at all.
- You are setting a geometry on your coreGui object but then call showMaximized followed by show.
Also using a custom thread only for a 5 second timer is way overkill.
What exactly do you want to do with your application ?
-
Not to sound rude but that code base is a bit messy:
- You have two **Gui objects in you main.cpp that are not used at all.
- You are setting a geometry on your coreGui object but then call showMaximized followed by show.
Also using a custom thread only for a 5 second timer is way overkill.
What exactly do you want to do with your application ?
@SGaist said in Switching between two ui forms / QMainWindow screens:
ou have two **Gui objects in you main.cpp that are not used at all.
You are setting a geometry on your coreGui object but then call showMaximized followed by show.Also using a custom thread only for a 5 second timer is way overkill.
What exactly do you want to do with your application ?Yes I know , this is kind of a PoC I am doing and this is what I want to achieve:
- Keep two separate GUIs (ui forms).
- When application starts, it should spawn a thread which will run timer and at the same time display first GUI on screen (happens in C'TOR).
- When the timer of the thread goes off, it will emit its SIGNAL and SLOT function of main will get called which will stop the first GUI and replace with second one.
Thanks
-
Which platform r u trying this ? Is it embedded box or desktop ? I have sample for ur use case. I can share you. It works perfectly.
-
Which platform r u trying this ? Is it embedded box or desktop ? I have sample for ur use case. I can share you. It works perfectly.
Hi, Its for embedded Linux.
-
Does you logic works on desktop platform ?
-
And why not just use a single shot QTimer ?
I really fail to see the use for that secondary thread except needless complexity.
-
And why not just use a single shot QTimer ?
I really fail to see the use for that secondary thread except needless complexity.
Hi,
This is just for PoC, BelowI created application with one QMainWindow class and two ui classes derived from QWidget. Then I used QStackedWidget to switch the ui forms but
I cannot see anything on screen.
Thank you for help,/Second UI */ namespace Ui { class RaptorCoreGUI; } class RaptorCoreGUI : public QWidget { Q_OBJECT public: explicit RaptorCoreGUI(QWidget *parent = 0); ~RaptorCoreGUI(); void configInitData(bool); void setlabel(QString); private: Ui::RaptorCoreGUI *ui; }; /*First UI*/ amespace Ui { class RaptorLrsGUI; } class RaptorLrsGUI : public QWidget { Q_OBJECT public: explicit RaptorLrsGUI(QWidget *parent = 0); ~RaptorLrsGUI(); void setlabel(QString); private: Ui::RaptorLrsGUI *ui; }; /*Base class derived from QMainWindow*/ class Base : public QMainWindow { Q_OBJECT public: RaptorLrsGUI *lrsGUI; RaptorCoreGUI *coreGUI; QStackedWidget *stackedWidget; QVBoxLayout *layout; ~Base(); explicit Base (QWidget *parent = 0); private slots: void rcvInitData(); }; /*Second UI CPP*/ RaptorCoreGUI::RaptorCoreGUI(QWidget *parent) : QWidget(parent), ui(new Ui::RaptorCoreGUI) { ui->setupUi(this); this->setAutoFillBackground(true); this->setStyleSheet("background-color:white;"); } RaptorCoreGUI::~RaptorCoreGUI() { delete ui; } void RaptorCoreGUI::setlabel(QString label) { qDebug() << "Main Thread(COREGUI): Setting Label\n"; ui->label->setText(label); } /*First UI cpp*/ RaptorLrsGUI::RaptorLrsGUI(QWidget *parent) : QWidget(parent), ui(new Ui::RaptorLrsGUI) { ui->setupUi(this); this->setAutoFillBackground(true); this->setStyleSheet("background-color:white;"); } RaptorLrsGUI::~RaptorLrsGUI() { qDebug() << "Main Thread: destroying the ui object \n"; delete ui; } void RaptorLrsGUI::setlabel(QString label) { qDebug() << "Main Thread(LSRGUI): Setting Label\n"; ui->label->setText(label); } /*main.cpp*/ Base::Base(QWidget *parent) : QMainWindow(parent, Qt::FramelessWindowHint) { qDebug() << "Base CTOR called\n"; QPalette pal = palette(); // retrieves the default palette for the widget, as defined by the app's style pal.setColor( QPalette::Window, Qt::white ); setPalette( pal ); setAutoFillBackground( true ); //Show the first screen, loading raptor status lrsGUI = new RaptorLrsGUI; lrsGUI->setlabel(QString("Loading Raptor Status...")); coreGUI = new RaptorCoreGUI; stackedWidget = new QStackedWidget(this); stackedWidget->addWidget(lrsGUI); stackedWidget->addWidget(coreGUI); stackedWidget->setCurrentIndex(0); setCentralWidget(stackedWidget); } Base::~Base() { qDebug() << "Main Thread: destroying base objects \n"; delete lrsGUI; delete coreGUI; delete stackedWidget; } void Base::rcvInitData() { qDebug()<< "Main Thread (CALLBACK): Display second screen\n"; stackedWidget->setCurrentIndex(1); } //! [1] int main(int argc, char *argv[]) { QApplication app(argc, argv); //Instantiate base class Base baseObj; //instantiate Client thread object ClientThread clientThread; qDebug() << "Connecting sendmsg and handle_callback1()\n"; QObject::connect(&clientThread, SIGNAL(sendInitData()), &baseObj, SLOT(rcvInitData()), Qt::QueuedConnection); qDebug() << "Main Thread: starting clockThread\n"; clientThread.start(); app.exec(); qDebug() << "Mian Thread: Quiting clockThread\n"; clientThread.quit(); qDebug() << "Main Thread: Waiting on clockThread \n"; clientThread.wait(); return 0; }
-
Is it me or are you missing a call to
baseObj.show();
in yourmain.cpp
? -
-
You're welcome !
Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)