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. [CLOSED] String and classes
Qt 6.11 is out! See what's new in the release blog

[CLOSED] String and classes

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.2k Views
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hello, I have two classes

    Class 1 = MainWindow

    Class 2 = Dialog

    Dialog contains textedit and should store string into MainWindow... How can I do that???

    How it should looks like

    Class 1
    QString test;

    Class 2
    void Dialog::onButtonClicked{
    test = uiDialog->textEdit->text();
    }

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Add a getter to your dialog and retrieve the string after you have called exec on it

      I would recommend going through Qt's examples and demos. You'll find a lot of valuable information to get you started

      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
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        I was trying to find example on Google but not very successfully...

        I used Refractor in Qt and it made Getter and Setter, but don't know what to do with it now...

        Dialog .h
        @#ifndef DIALOG_H
        #define DIALOG_H
        #include "mainwindow.h"
        #include "ui_mainwindow.h"
        #include <QDialog>

        namespace Ui {
        class Dialog;
        }

        class Dialog : public QDialog
        {
        Q_OBJECT

        public:
        explicit Dialog(QMainWindow *parent = 0);
        ~Dialog();
        Ui::MainWindow *ui;
        QString string;

        QString getString() const;
        void setString(const QString &value);

        private slots:
        void on_button_clicked();

        private:
        Ui::Dialog *uis;
        };

        #endif // DIALOG_H

        @

        Dialog .cpp
        @#include "dialog.h"
        #include "ui_dialog.h"
        #include "ui_mainwindow.h"
        #include "mainwindow.h"

        Dialog::Dialog(QMainWindow *parent) :
        QDialog(parent),
        uis(new Ui::Dialog)
        {
        uis->setupUi(this);
        }

        Dialog::~Dialog()
        {
        delete uis;
        }
        QString Dialog::getString() const
        {
        return string;
        }

        void Dialog::setString(const QString &value)
        {
        string = value;
        }

        void Dialog::on_button_clicked()
        {

        }
        @

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Why would you need MainWindow::Ui in your dialog ?

          @
          QString Dialog::getString() const
          {
          return uis->myLineEdit->text();
          }

          void Dialog::setString(const QString &value)
          {
          uis->myLineEdit->setText(value);
          }@

          I would recommend reading Qt's documentation/tutorials/examples before going further. You'll get a better grasp on how things work

          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
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            Oh I was testing something, thats why MainWindow::Ui is there...

            Where exactly do I have to read??? I went through few documentations but none of them explained use of getter/setter...

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

              I figured out I can design QDialog even without designer pretty well, therefore I won't need these functions at this moment...

              Thanks anyways

              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 Extensions
              • Unsolved