QlineEdit display of a string and a QDateTime variable.
-
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
-
@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_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? -
@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.
-
@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();
^ -
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.
-
Hi
Its just
QDateTime now = QDateTime::currentDateTime();
ui->lineEdit->setText( "Today is:" + now.toString() );