How can I display trme as a string ?
Could someone give me some code to be able to do that ?
I am using a TimeEdit window. So suppose someone edits it. I would like the editted time to show up in a mesage box.
How can I display trme as a string ?
Could someone give me some code to be able to do that ?
I am using a TimeEdit window. So suppose someone edits it. I would like the editted time to show up in a mesage box.
QString str = "time";
sorry couldn't resist.
RTFM
Qt has really good documentation. From within Qt Creator, Click on Help-Index and type QDateTime - that should help you on your way.
Hi
Hers the code for you
Well it does it . It displays 12:00 in a message box.
But it does not display the update time when the user edits the EditTime box.
I triedBut it gave a parameter error on timeChanged .Qt Code:
To copy to clipboard, switch view to plain text mode
I am flumoxed here.
You can't use timeChanged() the way you do.
It's a [signal] and you must connect it to a [slot].
ok. What i need is some way to retrieve the text from QTimeEdit and display it in a messagebox.
A pointer of QTimeEdit in the messagebox![]()
Here is the code:
Qt Code:
void calendartime:: display_message() { QMessageBox msgbox; QTimeEdit *timeEdit; msgbox.setText(timeInString) ; msgbox.exec(); }To copy to clipboard, switch view to plain text mode
I get the following error:
calendartime.cpp:44: error: request for member 'time' in 'timeEdit', which is of non-class type 'QTimeEdit*'
Try
(Note "timeEdit->" instead of "timeEdit.".)Qt Code:
To copy to clipboard, switch view to plain text mode
I get calendartime.cpp:44: error: base operand of '->' has non-pointer type 'QTimeEdit'
Then I tried this code
and it crashed withc process id 4192. I suspect this has to something with the pointer to QTimeEdit.Qt Code:
void calendartime:: display_message() { QMessageBox msgbox; QTimeEdit *timeEdit; msgbox.setText(text); msgbox.exec(); }To copy to clipboard, switch view to plain text mode
I am starting to think it can't be done..![]()
Last edited by Petr_Kropotkin; 27th January 2010 at 22:41.
Your allocating timeEdit on the stack and not initialising the object, so your dereferencing a random memory location. It's going to crash. Create the object with 'new' first.
eg. timeEdit = new QTimeEdit(this);
or don't use a pointer and use a value instead (omit the '*' in the declaration)
On closer look, 'timeEdit' is a pointer that is never initialized. You need to create the object or retrieve the time from somewhere. Do you have a QTimeEdit object somewhere else in your code?
It runs but then when you change the time it crashes and gives me : Visual C++ Runtime Error. It terminates in an unusal way.
I removed the message box to eee if things would run .
Last edited by Petr_Kropotkin; 28th January 2010 at 00:09.
I just did that
In the ui_ calendartime.h I added this line
In the calendartime.h I changed the function to
Qt Code:
To copy to clipboard, switch view to plain text mode
and in calendartime.cpp I changed the connnect function to
Qt Code:
To copy to clipboard, switch view to plain text mode
and here is display_message
Qt Code:
{ QMessageBox msgbox; msgbox.setText(text); msgbox.exec(); }To copy to clipboard, switch view to plain text mode
It ran but crashed.
Make a connection like this:
Qt Code:
connect(acceptButton, SIGNAL(clicked()), this, SLOT(display_message()));To copy to clipboard, switch view to plain text mode
Then:
In this case, timeEdit is the name of the QTimeEdit you used in your form.Qt Code:
void calendartime:: display_message() { QMessageBox msgbox; msgbox.setText(text); msgbox.exec(); }To copy to clipboard, switch view to plain text mode
And don't mess around in ui_ files.Changes you make there will be lost after compilation.
The original connect function was display_message().
Without declaring QTimeEdit, it crashed.
Here is the old version
It runs but does not display the changes from QTimeEditQt Code:
void calendartime:: display_message() { QMessageBox msgbox; QTimeEdit timeEdit; msgbox.setText(timeInString); msgbox.exec(); }To copy to clipboard, switch view to plain text mode
Last edited by Petr_Kropotkin; 28th January 2010 at 16:46.
So what *does* it do?
it jiust displays 12:00 pm
Which is correct, as you are creating a QTimeEdit and not passing in a QTime to set the time to, so the default is 12:00pm. If you wish to display a different value, pass in a QTime object which contains the appropriate time.
Bookmarks