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. Why report a error,winfinite recursion, when override QDataStream &operator<< and argument is QVector.
Forum Update on Monday, May 27th 2025

Why report a error,winfinite recursion, when override QDataStream &operator<< and argument is QVector.

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 713 Views
  • 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.
  • C Offline
    C Offline
    Crawl.W
    wrote on 28 Aug 2019, 12:40 last edited by
    #1

    Code as following:

    typedef QVector<WellDataAnalyzeInfo> ExpAnalysisResult;//WellDataAnalyzeInfo is a custom struct
    
    QDataStream &operator<<(QDataStream& out, const Analysis::ExpAnalysisResult& info)
    {
        out << info;
        return out;
    }
    

    The following code will have the same problem:

    QDataStream &operator<<(QDataStream& out, const QVector<int>& info)
    {
    out << info;
        return out;
    }
    

    But the following is normal:

    struct ExpAnalysisResult
    {
        QVector<int> ddd;
    };
    
    QDataStream &operator<<(QDataStream& out, const Analysis::ExpAnalysisResult& info)
    {
        out << info.ddd;
        return out;
    }
    
    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 28 Aug 2019, 15:52 last edited by
      #2

      @crawl-w said in Why report a error,winfinite recursion, when override QDataStream &operator<< and argument is QVector.:

      out << info;

      What do you think happens here?

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

      C 1 Reply Last reply 29 Aug 2019, 01:44
      3
      • C Christian Ehrlicher
        28 Aug 2019, 15:52

        @crawl-w said in Why report a error,winfinite recursion, when override QDataStream &operator<< and argument is QVector.:

        out << info;

        What do you think happens here?

        C Offline
        C Offline
        Crawl.W
        wrote on 29 Aug 2019, 01:44 last edited by
        #3

        @christian-ehrlicher Let each element in the container be written to a file respectively.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 29 Aug 2019, 04:28 last edited by
          #4

          No, it calls "QDataStream &operator<<(QDataStream& out, const Analysis::ExpAnalysisResult& info)" - why should it iterate over the container?

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

          C 1 Reply Last reply 29 Aug 2019, 05:20
          0
          • C Christian Ehrlicher
            29 Aug 2019, 04:28

            No, it calls "QDataStream &operator<<(QDataStream& out, const Analysis::ExpAnalysisResult& info)" - why should it iterate over the container?

            C Offline
            C Offline
            Crawl.W
            wrote on 29 Aug 2019, 05:20 last edited by
            #5

            @christian-ehrlicher "typedef QVector<WellDataAnalyzeInfo> ExpAnalysisResult;"Because ExpAnalysisResult is a QVector<T>.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 29 Aug 2019, 06:08 last edited by
              #6

              @crawl-w said in Why report a error,winfinite recursion, when override QDataStream &operator<< and argument is QVector.:

              Because ExpAnalysisResult is a QVector<T>.

              But you give the compiler already an operator for this - namely 'QDataStream &operator<<(QDataStream& out, const Analysis::ExpAnalysisResult& info)' - so why should another one be used when it finds an exact match for it?

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

              C 1 Reply Last reply 29 Aug 2019, 08:18
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 29 Aug 2019, 07:13 last edited by
                #7

                Hi,

                To add to @Christian-Ehrlicher

                @crawl-w said in Why report a error,winfinite recursion, when override QDataStream &operator<< and argument is QVector.:

                QDataStream &operator<<(QDataStream& out, const Analysis::ExpAnalysisResult& info)
                {
                out << info;
                return out;
                }

                The goal of this operator implantation is to serialise the content of your Analysis::ExpAnalysisResult object. Just writing out << info will basically be the operator trying to call itself.

                There's no automagical way to serialise your object. At some point you have to write down which fields should go in the stream.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • C Christian Ehrlicher
                  29 Aug 2019, 06:08

                  @crawl-w said in Why report a error,winfinite recursion, when override QDataStream &operator<< and argument is QVector.:

                  Because ExpAnalysisResult is a QVector<T>.

                  But you give the compiler already an operator for this - namely 'QDataStream &operator<<(QDataStream& out, const Analysis::ExpAnalysisResult& info)' - so why should another one be used when it finds an exact match for it?

                  C Offline
                  C Offline
                  Crawl.W
                  wrote on 29 Aug 2019, 08:18 last edited by Crawl.W
                  #8

                  @christian-ehrlicher @SGaist But the second code snippet is wrong,the third code snippet right. The third code snippet's info.ddd as same as the second code snippet's info and the first. About WellDataAnalyzeInfo, I have a alone operator implantation.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 29 Aug 2019, 08:57 last edited by
                    #9

                    As long as you declare, implement and register the QDataStream operator for your class. You don't have to implement anything special for QVector as it's already handled. You only have to care about your custom type.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    C 1 Reply Last reply 29 Aug 2019, 10:03
                    1
                    • S SGaist
                      29 Aug 2019, 08:57

                      As long as you declare, implement and register the QDataStream operator for your class. You don't have to implement anything special for QVector as it's already handled. You only have to care about your custom type.

                      C Offline
                      C Offline
                      Crawl.W
                      wrote on 29 Aug 2019, 10:03 last edited by Crawl.W
                      #10

                      @sgaist I got it, I needn't have implement operator for ExpAnalysisResult, just delete it.

                      1 Reply Last reply
                      0

                      1/10

                      28 Aug 2019, 12:40

                      • Login

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