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. QlineEdit display of a string and a QDateTime variable.
Forum Updated to NodeBB v4.3 + New Features

QlineEdit display of a string and a QDateTime variable.

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 919 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
    qt_emp
    wrote on 24 Oct 2019, 19:04 last edited by
    #1

    The following does not work: gives compiler error
    QDateTime now = QDateTime::currentDateTime();
    QlineEdit.setText("Today Is" & now);

    I tried: gives compiler error
    QlineEdit.setText("Today Is" & now.toString());

    I also tried: gives compiler error
    std::stringstream sstr;
    sstr << "Today is "<< now.toString();
    QlineEdit.setText( sstr.str() );

    the compiler error is:
    cannot convert "Today is" '(type 'const char[8] to type 'QDebug'
    QString qstr = "Today is " << now.toString();
    ^
    I am not using QDebug in the application at all.

    I want the lineEdit box to display Today is (whatever is in now)

    Any help will be appreciated

    Thanks emp1953

    A 1 Reply Last reply 24 Oct 2019, 19:26
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 24 Oct 2019, 19:11 last edited by
      #2

      @qt_emp said in QlineEdit display of a string and a QDateTime variable.:

      QlineEdit.setText("Today Is" & now);

      This is no C++ code at all - it would maybe work with visual basic.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • Q Offline
        Q Offline
        qt_emp
        wrote on 24 Oct 2019, 19:17 last edited by
        #3

        @qt_emp said in QlineEdit display of a string and a QDateTime variable.:

        std::stringstream sstr;
        sstr << "Today is "<< now.toString();
        QlineEdit.setText( sstr.str() );

        I'm using QT4.8 on RHEL6.
        This is c++ code. Any suggestions on why this is acting up?

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 24 Oct 2019, 19:23 last edited by
          #4

          @qt_emp said in QlineEdit display of a string and a QDateTime variable.:

          This is c++ code. Any suggestions on why this is acting up?

          It just looks like C++ code but shows that you never actually wrote C++.

          • QLineEdit is a class, you need an instance of a class to call a function of it
          • QLineEdit::setText() needs a QString, you try to pass a std::string - so you need to convert your string.

          Apart from this Qt4.8 is no longer supported so I would start with a recent Qt5 version.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          Q 1 Reply Last reply 25 Oct 2019, 14:13
          4
          • Q qt_emp
            24 Oct 2019, 19:04

            The following does not work: gives compiler error
            QDateTime now = QDateTime::currentDateTime();
            QlineEdit.setText("Today Is" & now);

            I tried: gives compiler error
            QlineEdit.setText("Today Is" & now.toString());

            I also tried: gives compiler error
            std::stringstream sstr;
            sstr << "Today is "<< now.toString();
            QlineEdit.setText( sstr.str() );

            the compiler error is:
            cannot convert "Today is" '(type 'const char[8] to type 'QDebug'
            QString qstr = "Today is " << now.toString();
            ^
            I am not using QDebug in the application at all.

            I want the lineEdit box to display Today is (whatever is in now)

            Any help will be appreciated

            Thanks emp1953

            A Offline
            A Offline
            anning
            wrote on 24 Oct 2019, 19:26 last edited by
            #5

            @qt_emp qt qstring connect shouldn't be +?

            1 Reply Last reply
            2
            • C Christian Ehrlicher
              24 Oct 2019, 19:23

              @qt_emp said in QlineEdit display of a string and a QDateTime variable.:

              This is c++ code. Any suggestions on why this is acting up?

              It just looks like C++ code but shows that you never actually wrote C++.

              • QLineEdit is a class, you need an instance of a class to call a function of it
              • QLineEdit::setText() needs a QString, you try to pass a std::string - so you need to convert your string.

              Apart from this Qt4.8 is no longer supported so I would start with a recent Qt5 version.

              Q Offline
              Q Offline
              qt_emp
              wrote on 25 Oct 2019, 14:13 last edited by
              #6

              @Christian-Ehrlicher I work in an industry where anything above QT4.8 has not been approved because of dept of defense security issues. So your suggestion to move to QT5 is not helpful. I know that QlineEdit is the name of the class. I just had that there to represent the widget(s) that I have named on the user form.
              So to satisfy the detractors how about this:

              QTimeDate now = QDateTime::currentDateTime();
              std::stringstream sstr;
              sstr << "Today is "<< now.toString();
              ui->lineedit_cal_output.setText( sstr.str() );

              compiler error is

              cannot convert "Today is" '(type 'const char[8] to type 'QDebug'
              QString qstr = "Today is " << now.toString();
              ^

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 25 Oct 2019, 14:40 last edited by Christian Ehrlicher
                #7

                Similar problem like before - std::stringstream can't handle a QString - you need to pass something std::stringstream can handle (like e.g. a std::string or const char*) - c++ basics.

                I just had that there to represent the widget(s)

                You should post useful code instead some pseudo-code if you're complaining about compiler errors.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                3
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 26 Oct 2019, 08:44 last edited by
                  #8

                  Hi
                  Its just
                  QDateTime now = QDateTime::currentDateTime();
                  ui->lineEdit->setText( "Today is:" + now.toString() );

                  1 Reply Last reply
                  3

                  1/8

                  24 Oct 2019, 19:04

                  • Login

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