Results 1 to 8 of 8

Thread: passing date from a dialog to another one

  1. #1
    Join Date
    Apr 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default passing date from a dialog to another one

    Hello,

    I have two dialogs. In the first one (testprogram) i can get data from the other one (dialog2). So when dialog2 pops up and returns a value, 'testprogram' dialog can use it. But now I want to reverse it. I want some data of 'testprogram' appear in the dateEdit object of 'dialog2'.

    Qt Code:
    1. void dialog2::dialog2_addbuttonClicked()
    2. {
    3. testprogram dialog;
    4. if (dialog.exec() == QDialog::Accepted)
    5. {
    6. m_ui->dialog2_dateEdit->setDate(dialog.adddatestring(QDate));
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    Error in the if... row: 'class testprogram' has no member named 'exec'

    I don't want to open the 'testprogram again, i was trying with these lines as these work fine in the other situation.
    To make myself more understandable:

    1. user launches program, 'testprogram' dialog opens.
    2. user sets a date in the dateEdit object, then pushes a button.
    3. That push makes 'dialog2' appear and in the dateEdit (or lineEdit, whatever) appears the date that user had set in the 'tesprogram' dialog.

    I am stuck at this, any help is appreciated.

  2. #2
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: passing date from a dialog to another one

    mmh... if I'm understanding correctly... I would just write some code in dialog2 which takes the value you need from testprogram. Let's say dateEdit is public, you may put in the constructor of dialog2 something like:
    Qt Code:
    1. dateEdit.setText(testprogram.dateEdit.text);
    To copy to clipboard, switch view to plain text mode 
    I used setText and text, but you can use the correct method provided by the control you're using. Is this what you needed?

  3. #3
    Join Date
    Apr 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: passing date from a dialog to another one

    Thanks for the answer. I created an image as demonstration:
    http://img707.imageshack.us/img707/2637/dialogo.png
    Green arrow: When I click on the add button, the task text gets into the tablewidget of the larger (i called it 'testprogram') window.
    Red arrow: When I change the date in the dateEdit i want that date to appear in the dateEdit of the smaller (I called it 'dialog2') dialog.

    Your code seems strange. I use arrows instead of points, but i want to sg like you wrote, i just don't know how to write the proper command.

    I wrote this: m_ui->dialog2_dateEdit->setText(?)

    If I wrote m_ui->dialog2_dateEdit instead of your "dateEdit", what shall i wrote instead of your "testprogram.dateEdit.text"? I don't know how to refer to the testprogram dialog.

  4. #4
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: passing date from a dialog to another one

    In fact you should have a reference to the first dialog. I don't know how you created dialog2, but it is possible to set a parent for that dialog, and that could be testprogram. In this case, you may write in testprogram something like this:
    Qt Code:
    1. dialog2 myDialog2(this);
    2. myDialog2.exec();
    To copy to clipboard, switch view to plain text mode 
    this means you can refer to testprogram in dialog2 more or less as:
    Qt Code:
    1. m_ui->dialog2_dateEdit->setText(((testprogram*)this->parent())->dateEdit->text());
    To copy to clipboard, switch view to plain text mode 
    Obviously the code is only to give an idea.

  5. #5
    Join Date
    Apr 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: passing date from a dialog to another one

    At first I created a Qt4 Gui Application, with Mainwindow.->testprogram
    Then I created a Qt Designer Form Class -> dialog2

    When I click on the addbutton on the 'testprogram' dialog it opens the 'dialog2' dialog. Some basic code:

    testprogram.cpp
    Qt Code:
    1. void testprogram::addClicked()
    2. {
    3. dialog2 dialog;
    4. if (dialog.exec() == QDialog::Accepted)
    5. {
    6. // here I get the data from dialog2 and put it into an textEdit. .e.g with a plaintext:
    7. QString taskdescrp = dialog.adddescription();
    8. ui->textEdit->setPlainText(taskdescrp);
    9. }
    10. else
    11. {
    12. return;
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    dialog2.h
    Qt Code:
    1. class dialog2 : public QDialog {
    2. Q_OBJECT
    3. public:
    4. dialog2(QWidget *parent = 0);
    5. ~dialog2();
    6. QString adddescription();
    7. public slots:
    8. void dialog2_addbuttonClicked();
    To copy to clipboard, switch view to plain text mode 

    dialog2.cpp
    Qt Code:
    1. void dialog2::dialog2_addbuttonClicked()
    2. {
    3. QString taskdesc = m_ui->dialog2_textEdit->toPlainText();
    4. accept();
    5. }
    6.  
    7. QString dialog2::adddescription()
    8. {
    9. return m_ui->dialog2_textEdit->toPlainText();
    10. }
    To copy to clipboard, switch view to plain text mode 

    I just don't know how to do it reverse.
    I think i should put something like you suggested into this part of the dialog2.cpp:

    Qt Code:
    1. dialog2::dialog2(QWidget *parent) :
    2. QDialog(parent),
    3. m_ui(new Ui::dialog2)
    4. {
    5. m_ui->setupUi(this);
    6. connect(m_ui->dialog2_addButton, SIGNAL(clicked()), this, SLOT(dialog2_addbuttonClicked()));
    7. m_ui->dialog2_lineEdit2->setText(((testprogram*)this->parent())->dateEdit->text());
    8. }
    To copy to clipboard, switch view to plain text mode 

    And I created this in the testprogram.cpp also:
    Qt Code:
    1. QString testprogram::adddatestring()
    2. {
    3. return ui->lineEdit4->text(); //i want this to be passed to a lineEdit of dialog2
    4. }
    To copy to clipboard, switch view to plain text mode 


    I hope you see something...

  6. #6
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: passing date from a dialog to another one

    Does this code work as expected? What I see is that you didn't pass the parent to the dialog2 instance in line 3 of testprogram.cpp. If dialog2 doesn't have a reference to its parent, then line 7 of dialog2.cpp cannot get the text.

  7. #7
    Join Date
    Apr 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: passing date from a dialog to another one

    I created a small file for this, and uploaded it to here:

    http://uploading.com/files/7deb9863/testprogram.rar/

    I hope this is much more understandable.

    what is working:
    when program launches, click on the From button, then write sg into lineEdit near "Send to tesprogram" then click Send, and it appears in the lineEdit near "From dialog2".

    what is not working:
    I write sg to the lineEdit near "To dialog2" then click on the From button, then when i click on the Get button, the content of that lineEdit should appear in the lineEdit near "Get from testprogram".
    (addbutton is not in use)

  8. #8
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: passing date from a dialog to another one

    Using this works:
    Qt Code:
    1. m_ui->dialog2_lineEdit->setText(((testprogram*)this->parent())->addtext());
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. passing data when closing a dialog
    By jimiq in forum Newbie
    Replies: 4
    Last Post: 4th November 2009, 16:48
  2. How to blur parent dialog when child dialog is displayed
    By abhilashajha in forum Qt Programming
    Replies: 4
    Last Post: 10th June 2009, 13:01
  3. Passing Pixmaps between MainWindow and Dialog
    By ramstormrage in forum Qt Programming
    Replies: 28
    Last Post: 20th April 2008, 13:32
  4. How to default Date-Edit Widget to system date
    By JohnToddSr in forum Qt Tools
    Replies: 4
    Last Post: 17th January 2007, 19:18
  5. control not passing from dialog to code
    By quickNitin in forum Newbie
    Replies: 3
    Last Post: 28th June 2006, 11:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.