And what is "Base"? Is it now a QMainWindow class? You haven't called the QMainWindow constructor from your Base class constructor.
Have you run your program in the debugger? Did you set a breakpoint on line 21 to see if this slot is ever called?
And what is "Base"? Is it now a QMainWindow class? You haven't called the QMainWindow constructor from your Base class constructor.
Have you run your program in the debugger? Did you set a breakpoint on line 21 to see if this slot is ever called?
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Base class is derived from QMainWindow as below:
Qt Code:
{ Q_OBJECT public: RaptorLrsGUI *lrsGUI; RaptorCoreGUI *coreGUI; QStackedWidget *stackedWidget; Base(); private slots: void rcvInitData(); };To copy to clipboard, switch view to plain text mode
I have put the log in the SLOT function and I can see it getting printed:
Qt Code:
void Base::rcvInitData() { qDebug()<< "Main Thread (CALLBACK): Display second screen\n"; this->stackedWidget->setCurrentIndex(1); }To copy to clipboard, switch view to plain text mode
Qt Code:
Base CTOR called Client Thread: Connecting timer object timeout signal with threads timerhit slot Client Thread: Starting timer objecti Client Thread: executing clock thread Client Thread: Emitting sendMsg signal Main Thread (CALLBACK): Display second screen Client Thread: Emitting sendMsg signal Main Thread (CALLBACK): Display second screenTo copy to clipboard, switch view to plain text mode
This is the thing that doesn't make any sense. Why would you have a QTimer emit a signal to show the same window more than once?Client Thread: Emitting sendMsg signal
Main Thread (CALLBACK): Display second screen
Client Thread: Emitting sendMsg signal
Main Thread (CALLBACK): Display second screen
If this second window is not being shown, then you are doing something else wrong somewhere, and you haven't posted enough code to demonstrate what that is.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
I actually made it work by adding "stackedWidget->showMaximized();" after setCurrentIndex(0) in constructor. But still I have couple of issues
1) I could not set the backgroung color of widgets to white , even after doing "setStyleSheet("background-color:white;");".
This I temp resolved by deriving the ui classes from QMainWindow instead of QWidget.
2) I am not able to remove the titlebar from the window.
Below is the complete code:
Qt Code:
/*First UI header*/ namespace Ui { class RaptorLrsGUI; } { Q_OBJECT public: ~RaptorLrsGUI(); private: Ui::RaptorLrsGUI *ui; }; /*Second UI header */ namespace Ui { class RaptorCoreGUI; } { Q_OBJECT public: ~RaptorCoreGUI(); void configInitData(bool); private: Ui::RaptorCoreGUI *ui; }; /*Base class header*/ { Q_OBJECT public: RaptorLrsGUI *lrsGUI; RaptorCoreGUI *coreGUI; QStackedWidget *stackedWidget; QVBoxLayout *layout; ~Base(); private slots: void rcvInitData(); }; /* Second UI cpp */ ui(new Ui::RaptorCoreGUI) { ui->setupUi(this); this->setAutoFillBackground(true); this->setStyleSheet("background-color:white;"); } RaptorCoreGUI::~RaptorCoreGUI() { delete ui; } { qDebug() << "Main Thread(COREGUI): Setting Label\n"; ui->label->setText(label); } /*First ui cpp*/ 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; } { qDebug() << "Main Thread(LSRGUI): Setting Label\n"; ui->label->setText(label); } /* Main.cpp */ { qDebug() << "Base CTOR called\n"; //Show the first screen, loading raptor status lrsGUI = new RaptorLrsGUI; coreGUI = new RaptorCoreGUI; //this->setCentralWidget(this->stackedWidget); // If uncommented it directly shows second UI stackedWidget->addWidget(lrsGUI); stackedWidget->addWidget(coreGUI); stackedWidget->setCurrentIndex(0); stackedWidget->showMaximized(); } 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[]) { //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; }To copy to clipboard, switch view to plain text mode
Do you understand that QMainWindow is supposed to be the only top-level window in your app, and that there is only supposed to be one instance of that class? You now have THREE classes that are derived from QMainWindow. QMainWindow is not a magic bullet class that you can derive anything from just to achieve some desired UI effect (like a different background color). And showMaximized() should never be called on a child window, only on a top-level window like QMainWindow.This I temp resolved by deriving the ui classes from QMainWindow instead of QWidget.
QMainWindow is not just a widget, it defines a framework and a set of behaviors for applications with a single top-level window and many child windows within it. You cannot just simply use a QMainWindow anywhere you want without running into problems somewhere along the line because you haven't followed the rules.
I have no idea what types of classes "RaptorLrsGUI" and "RaptorCoreGUI" are. If they aren't derived from QWidget, then that is an error. If you have a custom paintEvent() in these classes, then that is where you should implement the code to fill the background with whatever color you want. If you do not have a paintEvent(), then in the constructor for these classes you should have code like this:
Qt Code:
QPalette pal = palette(); // retrieves the default palette for the widget, as defined by the app's style setPalette( pal ); setAutoFillBackground( true );To copy to clipboard, switch view to plain text mode
Setting the appropriate colors in the palette as well as ensuring that the widget automatically clears its background and fills it with the chosen color on a paintEvent() is the right way to do it.
I think you need to take a step back and look at some of the many examples in Qt for QMainWindow-based apps. If you continue down the path you are taking, your PoC is going to turn out to be a "proof of buggy code" that acts in ways you can't explain and is confusing to debug.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Hi,
I very well know that QMainWindow is top level/parent window. That's what initially I did, when classes "RaptorLrsGUI" and "RaptorCoreGUI" are derived from QWidget and QStackedWidget is used , I don't see anything on screen, it goes blank. The below code is exactly as per suggested and it does not work.
Also I have changed the code to remove showMaximized on widget and use single shot timer.
Thanks for your patience..:-)
Qt Code:
{ qDebug() << "Base CTOR called\n"; QPalette pal = palette(); // retrieves the default palette for the widget, as defined by the app's style setPalette( pal ); setAutoFillBackground( true ); //Show the first screen, loading raptor status lrsGUI = new RaptorLrsGUI; //RaptorLrsGUI derived from QWidget coreGUI = new RaptorCoreGUI; //RaptorCoreGUI derived from QWidget stackedWidget->addWidget(lrsGUI); stackedWidget->addWidget(coreGUI); stackedWidget->setCurrentIndex(0); } 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); }To copy to clipboard, switch view to plain text mode
Rest of the code remain same as earlier.
You create the QStackedWidget, but you do not give it any parent. You do not tell your QMainWidget to use the QStackedWidget as its "centralWidget". Thus the QStackedWidget is never shown, so it is always invisible.
Line 16 should be:
Qt Code:
To copy to clipboard, switch view to plain text mode
and add a line at the end of the constructor:
Qt Code:
setCentralWidget( stackedWidget );To copy to clipboard, switch view to plain text mode
If you want the background of the Raptor* widgets to be white, this code needs to be moved to their constructors. It does nothing if you have it in the Base constructor:
Qt Code:
QPalette pal = palette(); // retrieves the default palette for the widget, as defined by the app's style setPalette( pal );To copy to clipboard, switch view to plain text mode
Edit: Actually, maybe this is incorrect. If you set the palette before creating the stacked and Raptor* widgets, it is possible that they will inherit the QPalette:: Window setting from the Base class.
Last edited by d_stranz; 26th September 2017 at 18:05.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
I made the changes the but still I can see white screen with title bar (screenshot attached) , below is the complete code.
Thanks you for all the help,
Qt Code:
/Second UI */ namespace Ui { class RaptorCoreGUI; } { Q_OBJECT public: ~RaptorCoreGUI(); void configInitData(bool); private: Ui::RaptorCoreGUI *ui; }; /*First UI*/ amespace Ui { class RaptorLrsGUI; } { Q_OBJECT public: ~RaptorLrsGUI(); private: Ui::RaptorLrsGUI *ui; }; /*Base class derived from QMainWindow*/ { Q_OBJECT public: RaptorLrsGUI *lrsGUI; RaptorCoreGUI *coreGUI; QStackedWidget *stackedWidget; QVBoxLayout *layout; ~Base(); private slots: void rcvInitData(); }; /*Second UI CPP*/ ui(new Ui::RaptorCoreGUI) { ui->setupUi(this); this->setAutoFillBackground(true); this->setStyleSheet("background-color:white;"); } RaptorCoreGUI::~RaptorCoreGUI() { delete ui; } { qDebug() << "Main Thread(COREGUI): Setting Label\n"; ui->label->setText(label); } /*First UI cpp*/ 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; } { qDebug() << "Main Thread(LSRGUI): Setting Label\n"; ui->label->setText(label); } /*main.cpp*/ { qDebug() << "Base CTOR called\n"; QPalette pal = palette(); // retrieves the default palette for the widget, as defined by the app's style setPalette( pal ); setAutoFillBackground( true ); //Show the first screen, loading raptor status lrsGUI = new RaptorLrsGUI; coreGUI = new RaptorCoreGUI; 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[]) { //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; }To copy to clipboard, switch view to plain text mode
I think we need to start from zero, because something is clearly wrong with what you are doing now.
Please write and run these two programs. You can simply comment out the lines in your current main.cpp and replace them with these lines:
Qt Code:
#include <QtWidgets/QApplication> #include "RaptorCoreGUI.h" int main(int argc, char *argv[]) { RaptorCoreGUI w; w.show(); return a.exec(); }To copy to clipboard, switch view to plain text mode
Qt Code:
#include <QtWidgets/QApplication> #include "RaptorLrsGUI.h" int main(int argc, char *argv[]) { RaptorLrsGUI w; w.show(); return a.exec(); }To copy to clipboard, switch view to plain text mode
In each case, do you see the windows you expect to see?
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Yes I can see the windows (attached)
IMG-4835 --> coreGUI
ING-4836 --> lrsGUI
OK, good. The problem is not with your Raptor* widgets.
Next step. Do you see the RaptorLrsGUI window when you run this code?
Qt Code:
#include <QtWidgets/QApplication> #include <QtWidgets/QMainWindow> #include <QtWidgets/QStackedWidget> #include "RaptorLrsGUI.h" int main(int argc, char *argv[]) { QMainWindow w; RaptorLrsGUI * pLrs = new RaptorLrsGUI; pStack->addWidget( pLrs ); w.setCentralWidget( pStack ); w.show(); return a.exec(); }To copy to clipboard, switch view to plain text mode
If it does, substitute "w.showMaximized()" for "w.show()". Does it still work?
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Bookmarks