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] Data exchange between modal forms
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Data exchange between modal forms

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

    Hi,

    As the title suggests, I want to exchange data between two modal forms : mainForm and previewForm.

    The fist one, mainForm, is created and called in the main.cpp :
    @int main(int argc,char *argv[])
    {
    QApplication mainApplication(argc,argv);
    mainForm form;
    form.show();
    return mainApplication.exec();
    }@

    The second one, previewForm, is created and called when a button in the mainForm is clicked :
    @void mainForm::openPreviewForm()
    {
    previewForm preview;
    QObject::connect(this, SIGNAL(sendPath(QString)), preview, SLOT(preview.receivePath(QString)));
    preview.setModal(true);
    preview.exec();
    }@

    As I want to pass a QString from the mainForm to the previewForm, I created a public signal in the mainForm class :

    @void sendPath(QString);@

    ... and a public slot in the previewForm class :

    @void receivePath(QString);@

    I got a problem when i try to connect both using :
    @QObject::connect(this,SIGNAL(sendPath(QString)),preview,SLOT(preview.receivePath(QString)));@

    Do you have ideas how to fix this ?

    Thanks !

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

      Hi,

      Your slot name is wrong, it should be
      @SLOT(receivePath(QString))@

      but anyway, it's useless since your dialog is modal and lives only until exec returns. You should simply call receivePath with the value you want 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
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        It should be
        @
        QObject::connect(this, SIGNAL(sendPath(QString)), preview, SLOT(receivePath(QString)));
        @
        Notice no "preview." in the SLOT .

        Edit Yeah, um, what SGaist said :)

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Raphyy
          wrote on last edited by
          #4

          Thanks for your replies.

          So I got :
          @void mainForm::openPreviewForm()
          {
          previewForm preview;
          QObject::connect(this, SIGNAL(sendPath(QString)), preview, SLOT(receivePath(QString)));
          preview.setModal(true);
          preview.exec();
          }@

          ... and the following error :

          bq. mainForm.cpp:105:90: error: no matching function for call to 'mainForm::connect(mainForm* const, const char [19], previewForm&, const char [22])'

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

            preview is not a pointer, so it should be &preview.

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

              Thanks, it is better !

              I updated openPreview like so :

              @void mainForm::openPreviewForm()
              {
              previewForm preview;
              QObject::connect(this, SIGNAL(sendPath(QString)), &preview, SLOT(receivePath(QString)));
              emit sendPath(pathUserFileInput);
              QMessageBox::information(this,"Video Path",pathUserFileInput);
              preview.setModal(true);
              preview.exec();
              }@

              But I don't know how I should implement receivePath(QString).

              Other question : I have to send back a float to the parent form, can I do it using something like this (if I create corresponding signals and slots) :

              @QObject::connect(this, SIGNAL(sendTime(double)), &form, SLOT(receiveTime(double)));@

              Thanks !

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

                There's really no need for the connection and emit just call

                @receivePath(pathUserFileInput);@

                The implementation is up to you. Only you know what you want to do in receivePath.

                Your preview form doesn't need to know anything about your mainForm. So you should do the connection ins openPreviewForm.

                @connect(&preview, SIGNAL(sendTime(double)), this, SLOT(receiveTime()));@

                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
                • R Offline
                  R Offline
                  Raphyy
                  wrote on last edited by
                  #8

                  Ok thanks, I'll try it.

                  So I did this :
                  @void previewForm::receivePath(QString pathVideo)
                  {
                  pathUserFileInput = &pathVideo;
                  }@

                  Because I got this :
                  @class previewForm : public QDialog
                  {
                  Q_OBJECT
                  public:
                  [...]
                  QString *pathUserFileInput;
                  [...]@

                  The app crashes when I'm using *pathUserFileInput, is it the good way to get data from a slot ?

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

                    Please, have a look at Qt's examples and documentation. They will show you how to use QString and handle parameters when using signals and slots. What you do right now is taking the address of a temporary object, thus the crash.

                    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
                    • R Offline
                      R Offline
                      Raphyy
                      wrote on last edited by
                      #10

                      Hi,

                      I finally found the solution using what you told me and this link :
                      "http://stackoverflow.com/questions/17691669/cannot-receive-data-when-using-signal-slot-in-qt":http://stackoverflow.com/questions/17691669/cannot-receive-data-when-using-signal-slot-in-qt

                      Thanks !

                      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