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. How to set QDate global variables
Qt 6.11 is out! See what's new in the release blog

How to set QDate global variables

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 935 Views 3 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.
  • abuzerA Offline
    abuzerA Offline
    abuzer
    wrote on last edited by A Former User
    #1

    Hello everyone, this is my first time here to ask something.
    I have some editDate in ui, in GUI, and it is troublesome to set a QDate variable for every declaration.
    to Explain more clearly, I have the following:
    void MainWindow::on_pushButtonTestDate_clicked()
    {
    QDate A = ui->dateEditA->date();
    QDate B = ui->dateEditB->date();
    // ........some codes
    }

    void MainWindow::on_pushButtonTestDate2_clicked()
    {
    QDate A = ui->dateEditA->date();
    QDate B = ui->dateEditB->date();
    // ........some codes

    }

    My question is:
    How to make those QDate A, QDate B etc. global variable, define one time somewhere and can be used in every "void MainWindow::...."?

    Not quite sure if I expressed easily to be understood or not.
    But this problem really really stuck me for a lot of days, and made me not able to move on for the work....

    Thank You All!

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

      Hi and welcome
      To make a variable available to all function of mainwindow ,
      you just need to make it part of the class.
      so in mainwindow.h
      class Mainwindow:: public QMianwindow {
      private:
      QDate A;
      QDate b;
      };

      Its called a member variable. and is "global" to all functions of the class.

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

        Hi and welcome to devnet,

        To add to @mrjj, you will also have to keep them updated, which is easily done using signals and slots.

        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

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved