Important: Please read the Qt Code of Conduct -

Access MainWindow from different class

  • I do have the following classes:
    @#include <QApplication>
    #include <QComboBox>
    #include "mainwindow.h"
    MainWindow *w;
    int main(int argc, char *argv[])
    QApplication a(argc, argv);
    MainWindow w;;

    return a.exec&#40;&#41;;



    @#include "mainwindow.h"

    wtr = new WindowTitleReader();
    this->setWindowTitle("Selected Window Title Demo");



    In WindowTitleReader i would like to add a QComboBox to MainWindow.
    I tried this Code:
    @ MainWindow * win = (MainWindow *) QApplication::activeWindow();
    QComboBox * combo = new QComboBox(win);@

    But it doesn't add my QComboBox to MainWindow.

    Any idea?

  • Lifetime Qt Champion


    You are taking the wrong approach, please have a look at the examples and demos that comes with Qt. They'll show in details how to build a GUI

Log in to reply