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. SOLVED: Edit dialog from MainWindow
Forum Updated to NodeBB v4.3 + New Features

SOLVED: Edit dialog from MainWindow

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 2.0k 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.
  • Q Offline
    Q Offline
    Qatto
    wrote on last edited by
    #1

    Hello,

    I have been trying to set the text of a dialog/designer form that has no class but is called from the MainWindow class when a dialog button is clicked. If it's possible how would you got about it? The slot change_text() sets the content for ap.lineEdit
    So far the connector won't call change_text() probably because the dialog has been executed already.

    @void MainWindow::launch_dialog()
    {
    QDialog *diag = new QDialog;
    Ui::Dialog ap;
    ap.setupUi(diag);
    diag->setModal(true);
    diag->exec();

    connect(ap.pushButton, SIGNAL(clicked()), this, SLOT(change_text()));
    

    }@

    Web/Desktop Developer

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      You can connect before exec()

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Qatto
        wrote on last edited by
        #3

        Connecting before exec() crashes the app. Please look at my change_text() and advise how it's supposed to be

        @void MainWindow::change_text()
        {
        Ui::Dialog av;
        av.pushButton->setText("clicked");
        }@

        Web/Desktop Developer

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          Qatto
          wrote on last edited by
          #4

          Ok, got it. ap must be global

          Web/Desktop Developer

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

            Hi,
            No ap must not be global.

            What JKSH meant is that you should have moved the connect statement just before calling exec

            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
            • Q Offline
              Q Offline
              Qatto
              wrote on last edited by
              #6

              The problem is that declaring another ap inside the slot crashes the application. By global I meant ap should be declared inside the MainWindow class declaration not outside.

              Web/Desktop Developer

              1 Reply Last reply
              0
              • JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #7

                [quote author="Qkato" date="1376606459"]The problem is that declaring another ap inside the slot crashes the application.[/quote]That crash is not caused by the code you posted. It's probably a bug somewhere else that causes memory corruption.

                [quote]By global I meant ap should be declared inside the MainWindow class declaration not outside.[/quote]Yes, that's what you need to do. The correct term is "member variable", not "global".

                [quote author="Qkato" date="1376519112"]
                @
                void MainWindow::launch_dialog()
                {
                QDialog *diag = new QDialog;
                Ui::Dialog ap;
                ap.setupUi(diag);
                diag->setModal(true);
                diag->exec();

                ...
                }
                @
                [/quote]Your original code has a memory leak -- diag is never deleted. Make sure you clean up properly.

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                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