Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Access MainWindow from different class
Forum Updated to NodeBB v4.3 + New Features

Access MainWindow from different class

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 719 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    peili
    wrote on 21 Jun 2013, 18:26 last edited by
    #1

    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;
    w.show();

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

    }
    @

    and

    @#include "mainwindow.h"

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

    MainWindow::~MainWindow()
    {

    }@

    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?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 21 Jun 2013, 19:36 last edited by
      #2

      Hi,

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      1/2

      21 Jun 2013, 18:26

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved