Results 1 to 19 of 19

Thread: No match for operator>>

  1. #1
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default No match for operator>>

    Hi. I've got a problem. I want to read something, and have got a piece of code:
    Qt Code:
    1. QDataStream in(&file);
    2. in.setVersion(QDataStream::Qt_4_1);
    3.  
    4. QTableWidget *tableWidget;
    5. QTableWidget *tableWidget_2;
    6. QTableWidget *tableWidget_3;
    7. QTableWidget *tableWidget_4;
    8. QTableWidget *tableWidget_5;
    9. QTableWidget *tableWidget_6;
    10. QTableWidget *tableWidget_7;
    11.  
    12. MainWindow::clear();
    13.  
    14.  
    15.  
    16. in >> tableWidget >> tableWidget_2 >> tableWidget_3 >> tableWidget_4 >> tableWidget_5 >> tableWidget_6 >> tableWidget_7;
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: No match for operator>>

    Quote Originally Posted by Salazaar View Post
    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.

    Quote Originally Posted by Salazaar View Post
    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.

  3. #3
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: No match for operator>>

    Quote Originally Posted by jacek View Post
    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?
    Quote Originally Posted by jacek View Post
    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

  4. #4
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: No match for operator>>

    And if it was lineEdit, would it work?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: No match for operator>>

    Quote Originally Posted by Salazaar View Post
    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.

    Quote Originally Posted by Salazaar View Post
    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.

  6. #6
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: No match for operator>>

    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

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: No match for operator>>

    Quote Originally Posted by Salazaar View Post
    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. A hint: the property is called "text".
    J-P Nurmi

  8. #8
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: No match for operator>>

    And in order not to post next thread, if I have a bool function, can I call return false; in few if() ? I mean:
    Qt Code:
    1. if (beaufortBox->isChecked() && beaufortBox_2->isChecked())
    2. {
    3. int ret = QMessageBox::Information(this, tr("Speed Units Converter"),
    4. tr("You can't convert value to the same unit"),
    5. QMessageBox::Ok | QMessageBox::Default);
    6. return false;
    7. }
    8.  
    9. if (beaufortBox_2->isChecked() && beaufortBox_3->isChecked())
    10. {
    11. int ret = QMessageBox::Information(this, tr("Speed Units Converter"),
    12. tr("You can't convert value to the same unit"),
    13. QMessageBox::Ok | QMessageBox::Default);
    14. return false;
    15. }
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: No match for operator>>

    Yes, you can have many return points.

  10. #10
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: No match for operator>>

    Thanks Regards

  11. #11
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: No match for operator>>

    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.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: No match for operator>>

    Quote Originally Posted by Salazaar View Post
    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?

    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?

  13. #13
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: No match for operator>>

    Is something like this correct?
    Qt Code:
    1. QString text (lineEdit) const
    To copy to clipboard, switch view to plain text mode 
    is that the "text method"?

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: No match for operator>>

    No, it doesn't make any sense.

    Qt Code:
    1. QLineEdit *myEdit;
    2. //...
    3. QString xxx = myEdit->text();
    To copy to clipboard, switch view to plain text mode 

    Please learn a bit of C++...

  15. #15
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: No match for operator>>

    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

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: No match for operator>>

    Quote Originally Posted by Salazaar View Post
    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...

  17. #17
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: No match for operator>>

    But text can be an integer. So how can I operate on integers which are in lineEdit?

  18. #18
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: No match for operator>>

    Quote Originally Posted by Salazaar View Post
    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.
    J-P Nurmi

  19. #19
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: No match for operator>>

    Thanks, I'll read it

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.