Get Date from one Class to another

  • Hi Guys,

    i have a Gui where the user can Type a date into a Date/Time Edit.
    Then i have Button. When this Button ist clicked the scatter example of QtDataVisualization starts.

    so I have two classes.
    The MainWIndow Class and the ScatterDataModifier Class.

    In the Scatter Example there is a Function to add Data to the Plot. It use the ScatterDataModifier class.

    Now i want to use the Date from my MainWindow in this Function.

    I tried almos everything but i get allthe time other values like - 5473537 or sth like that.

    Example :
    void ScatterDataModifier::addData()
    MainWindow Test;

    int Year = Test.ui->TimeFromUser->date().year();


    Can sb please help me ?

  • Qt Champions 2017

    You create a new MainWindow in the function.
    That is NOT the one on the screen where the user input data.

    Do you create the ScatterDataModifier window
    in the (real) Mainwindow class?

    What you would normally do it just use signals and slots and hook up the
    ScatterDataModifier and mainwindow so Mainwindowcan tell ScatterDataModifier
    about new data. OR reverse.

    What you do now is to create a new local copy of MainWindow and its never shown on screen and
    is delete as soon as addData(). So that is not how to do it.

  • @mrjj

    1. Do you maybe have an example how to use the signal and slots to solve my problem ?
    2. If i dont create the ScatterDatamodifer window in the MainWindow... How can I open a Plot with a Button on the MainWindow with Data from the MainWindow ??

  • Qt Champions 2017


    Not directly. All samples uses signals and slots
    so good start is

    • How can I open a Plot with Button on the MainWindow
      what is "a plot" ?
      If other class, you will simply new it and show it.

  • @mrjj so i read the documentation and i m not sure what to do now :(

    i have two classes the mainwindow class and the scatterdatamodifier class.... in the mainwindow class i get the date from the User(Date/Time Edit)..... How can i get this date in the scatterdatamodifer class ??
    or a little bit more specific... i have a function in the scatterdatamodifier class and i want to get the current Date from the Mainwindow.

    Sry for the stuid question but i dont get it :/

  • Qt Champions 2017

    Hi, can you zip the project and share here?
    Just paste link here.

    I need to see what you have where etc.
    Much easier to explain how to do it.

    As i understand u have a default gui project with the normal mainwindow.
    Then you added the "window" from scatter sample it sounds like.

    But in this case, it just easier to see. :)

    Dont worry. it is not very complicated.
    Its more a matter where you do it from as to use signals you need a place where
    both objects exits.

    -Sry for the stuid question but i dont get it :/
    Its not stupid and its ok as you did try to read docs :)

  • declare inside ScatterDataModifier

    void setDate(const QDate& val){m_date=val;}
    const QDate& date() const {return m_date;}
    QDate m_date;

    now from MainWindow call setDate to pass the date to the ScatterDataModifier instance

  • Hi Vronin .. thanks for your answer

    I tried your solution but i get an error that the ScatterDataModifier Class has no Constructor.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.