I don't think we can help you if you show us code that does something different than the one you are actually using...
If the two windows are never shown together maybe you should use a QStackedWidget instead of two widgets?
Anyway... if I wanted to have a mechanism for switching windows, I'd do it more or less like this:
class Dispatcher
: public QObject { Q_OBJECT
public:
m_windows << win;
if(m_current == -1) {
setWindow(0);
}
}
public slots:
void next() {
setWindow(m_current+1 % m_windows.count());
}
void prev() {
setWindow(m_current-1 % m_windows.count());
}
void setWindow(int which) {
if(m_current == which) return;
if(m_current!=-1) {
m_windows.at(m_current)->hide();
}
m_current = which;
m_windows.at(m_current)->show();
qApp->processEvents(); // optionally force event processing (don't unless sure it's required)
}
private:
QList<QWidget *> m_windows;
int current = -1;
};
class Dispatcher : public QObject {
Q_OBJECT
public:
void addWindow(QWidget *win) {
m_windows << win;
if(m_current == -1) {
setWindow(0);
}
}
public slots:
void next() {
setWindow(m_current+1 % m_windows.count());
}
void prev() {
setWindow(m_current-1 % m_windows.count());
}
void setWindow(int which) {
if(m_current == which) return;
if(m_current!=-1) {
m_windows.at(m_current)->hide();
}
m_current = which;
m_windows.at(m_current)->show();
qApp->processEvents(); // optionally force event processing (don't unless sure it's required)
}
private:
QList<QWidget *> m_windows;
int current = -1;
};
To copy to clipboard, switch view to plain text mode
Then it's just a matter of connecting a signal to one of the slots defined in the dispatcher.
Bookmarks