PDA

View Full Version : No match for operator>>



Salazaar
10th June 2007, 19:35
Hi. I've got a problem. I want to read something, and have got a piece of code:


QDataStream in(&file);
in.setVersion(QDataStream::Qt_4_1);

QTableWidget *tableWidget;
QTableWidget *tableWidget_2;
QTableWidget *tableWidget_3;
QTableWidget *tableWidget_4;
QTableWidget *tableWidget_5;
QTableWidget *tableWidget_6;
QTableWidget *tableWidget_7;

MainWindow::clear();



in >> tableWidget >> tableWidget_2 >> tableWidget_3 >> tableWidget_4 >> tableWidget_5 >> tableWidget_6 >> tableWidget_7;

and errors, that 'no match for operator>>'
Details:
http://allyoucanupload.webshots.com/v/2005716727206050865
sorry for the screen, but I don't know how to copy the compilation log from prompt. Regards

jacek
10th June 2007, 19:56
and errors, that 'no match for operator>>'
As the compiler told you, there is no operator >> which reads a pointer to QTableWidget from a data stream, so you have to write one yourself or find some other way to read the data you want.

Note that passing pointers through a data stream isn't a good idea, especially if you plan to store that stream in a file. Also you can't pass widgets through QDataStream.


sorry for the screen, but I don't know how to copy the compilation log from prompt.
I've already told you to look in the menu that opens after you click the C:\ icon in the upper-left corner.

Salazaar
10th June 2007, 20:05
so you have to write one yourself or find some other way to read the data you want.
Hmm... Do you know how to do it?

Note that passing pointers through a data stream isn't a good idea, especially if you plan to store that stream in a file. Also you can't pass widgets through QDataStream.

What do you mean? How would it look like without passing pointers (because I don't understand what do you mean in this case) Regards

Salazaar
10th June 2007, 20:33
And if it was lineEdit, would it work?

jacek
10th June 2007, 22:32
What do you mean? How would it look like without passing pointers (because I don't understand what do you mean in this case)
A pointer holds an address in memory at which some object is located. That address is valid only for the given process, i.e. it's meaningless for other processes and also it's meaningless after the process exits. So usually there is no point in storing it.


And if it was lineEdit, would it work?
No, lineEdit is a widget too and you can't copy widgets. You should send the data instead (a QString in case of line edit).

If you want to store and later restore the contents of a QTableWidget, try storing the data itself, not the whole widget.

Salazaar
11th June 2007, 18:04
So how could it be without passing pointers? And the second question is, if I have a lineEdit called, let's say, lineEdit. And how to call the string which is in this lineEdit? Regards

jpn
11th June 2007, 18:19
And the second question is, if I have a lineEdit called, let's say, lineEdit. And how to call the string which is in this lineEdit? Regards
Please, read the docs (http://doc.trolltech.com/4.3/qlineedit). A hint: the property is called "text".

Salazaar
11th June 2007, 18:42
And in order not to post next thread, if I have a bool function, can I call return false; in few if() ? I mean:

if (beaufortBox->isChecked() && beaufortBox_2->isChecked())
{
int ret = QMessageBox::Information(this, tr("Speed Units Converter"),
tr("You can't convert value to the same unit"),
QMessageBox::Ok | QMessageBox::Default);
return false;
}

if (beaufortBox_2->isChecked() && beaufortBox_3->isChecked())
{
int ret = QMessageBox::Information(this, tr("Speed Units Converter"),
tr("You can't convert value to the same unit"),
QMessageBox::Ok | QMessageBox::Default);
return false;
}

wysota
11th June 2007, 18:52
Yes, you can have many return points.

Salazaar
11th June 2007, 18:54
Thanks ;) Regards

Salazaar
12th June 2007, 12:39
And reffering to lineEdit's text, here's quote from docs:

This property holds the line edit's text.

Setting this property clears the selection, clears the undo/redo history, moves the cursor to the end of the line and resets the modified property to false. The text is not validated when inserted with setText().

The text is truncated to maxLength() length.

Access functions:

*
QString text () const
*
void setText ( const QString & )

See also insert() and clear().

access functions doesn't say how to refer to lineEdit's text. QString text () const it's just a declaration of a string. void setText ( const QString & ) is to set the lineEdit's text. And I still don't know how to operate on lineEdit's text.

wysota
12th June 2007, 13:14
access functions doesn't say how to refer to lineEdit's text.
Hmm? Do you know the meaning of the word "access"?


QString text () const it's just a declaration of a string.
Hmm? :confused::confused::confused::confused:

It's a declaration of a function/method that is called "text", returns a "QString" object and takes no arguments (implicit void).


void setText ( const QString & ) is to set the lineEdit's text.
Correct.


And I still don't know how to operate on lineEdit's text.
How about just trying to use the "text()" method?

Salazaar
12th June 2007, 13:30
Is something like this correct?

QString text (lineEdit) const
is that the "text method"?

wysota
12th June 2007, 13:39
No, it doesn't make any sense.


QLineEdit *myEdit;
//...
QString xxx = myEdit->text();

Please learn a bit of C++...

Salazaar
12th June 2007, 13:43
Thanks, now's clear. And if in lineEdit is an integer, I should use int (quint) instead of QString, right?
edit:
this problem wasn't about my c++ skills, but logical methods, I had no idea about it

wysota
12th June 2007, 15:55
Thanks, now's clear. And if in lineEdit is an integer, I should use int (quint) instead of QString, right?
No. if lineEdit is an integer then it already holds its own value.


edit:
this problem wasn't about my c++ skills, but logical methods, I had no idea about it
A lame excuse is better than no excuse... :eek:

Salazaar
12th June 2007, 16:48
But text can be an integer. So how can I operate on integers which are in lineEdit?

jpn
12th June 2007, 17:11
But text can be an integer. So how can I operate on integers which are in lineEdit?
Search QString docs and pick a method that converts the string to int.

Salazaar
12th June 2007, 17:48
Thanks, I'll read it