Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] manipulating qmainwindow widget through qdialog
Qt 6.12 LTS is out! See what's new in the release blog

[SOLVED] manipulating qmainwindow widget through qdialog

Scheduled Pinned Locked Moved General and Desktop
17 Posts 4 Posters 13.5k 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.
  • X Offline
    X Offline
    xeroblast
    wrote on last edited by
    #8

    i found this : http://www.qtcentre.org/threads/24755-How-to-add-data-into-the-QTableWidget
    but i get the following error : src/dialog.cpp:5: error: class 'Dialog' does not have any field named 'm_table'

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xeroblast
      wrote on last edited by
      #9

      solved it on my own :

      mainwindow.cpp
      @
      MainWindow::openDialog()
      {
      Dialog d(this, tableWidget);
      d.exec();
      }
      @
      dialog.cpp
      @
      QTableWidget *p_table;
      Dialog::Dialog(QWidget * parent , QTableWidget * table) : QDialog(parent)
      {
      setupUi(this);
      p_table = table;
      }
      @

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #10

        Hi,

        and that's exaclty how to get the pointer to the parent:

        @
        QTableWidget *p_table;
        Dialog::Dialog(QWidget * parent , QTableWidget * table) : QDialog(parent)
        {
        setupUi(this);
        p_table = table;
        }
        @

        The parent pointer. That could be cast to the MainWindow class. Or the main window could make a connect to a custom signal:

        @
        MainWindow::openDialog()
        {
        Dialog d(this, tableWidget);
        connect(&d, SIGNAL(MyCustomSignal(...)), this, SLOT(MySlotToAddSomeStuff(...)));
        d.exec();
        }@

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • X Offline
          X Offline
          xeroblast
          wrote on last edited by
          #11

          really thanx...

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #12

            Using signals and slots would be the better way, IMHO. And mor Qt'ish, too.

            This also has the advantage, that your dialog needs not to know anything about your list widget. In case you change your mind and replace the list widget by another widget, you only have to change the main windows implementation, but not the dialogs, as the signal remains the same.

            Basically the code is like this:

            dialog.h
            @
            class Dialog: public QDialog {
            public:
            Dialog(QWidget *parent);
            // ... more stuff

            protected slots:
            void saveButtonClicked();

            signals:
            void requestNewEntry(const QString &name, int amount, QDate date);
            }
            @

            dialog.cpp
            @
            Dialog::Dialog(QWidget *parent) : QDialog(parent)
            {
            // do your usual stuff here
            connect(saveButton, SIGNAL(clicked()), this, SLOT(saveButtonClicked()));
            }

            void Dialog::saveButtonClicked()
            {
            QString name = lineEdit->text();
            int amount = intSpinBoxl->value();
            QDate date = dateEdit->date();
            emit requestNewEntry(name, amount, date);
            }
            @

            mainwindow.h
            @
            class MainWindow: public QMainWindow {
            public:
            // constructors etc.

            public slots:
            void addEntry(const QString &name, int amount, QDate date);

            protected slots:
            void showDialog();
            }
            @

            mainwindow.cpp
            @
            void MainWindow::openDialog()
            {
            Dialog *d = new Dialog(this);
            connect(d, SIGNAL(requestNewEntry(QString, int, QDate)), this, SLOT(addEntry(QString, int, QDate)));
            d->show()
            }

            void MainWindow::addEntry(const QString &name, int amount, QDate date)
            {
            // create the items here depending on the value
            QListItem *i1 = new QListItem(val1);
            table->setItem(row, col, i1)
            }
            @

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dangelog
              wrote on last edited by
              #13

              I like the fact that I write how the solution should be, and someone else writes the corresponding code :-D

              Software Engineer
              KDAB (UK) Ltd., a KDAB Group company

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #14

                [quote author="peppe" date="1292491829"]I like the fact that I write how the solution should be, and someone else writes the corresponding code :-D[/quote]

                Shouldn't that be always the case in a our ideal world? ;-)

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  giesbert
                  wrote on last edited by
                  #15

                  Can I borrow you for some time? I also need people, writing the correct code for my problems :-)))

                  Nokia Certified Qt Specialist.
                  Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #16

                    You might be lucky, I'm a rent-that-coding-guy :-)

                    1 Reply Last reply
                    0
                    • X Offline
                      X Offline
                      xeroblast
                      wrote on last edited by
                      #17

                      i like this forum... there's a lot of help... just like the codeigniter forum... :D

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt
                      • Unsolved