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. Conversion of Qvector<qreal> to QVariant fails
QtWS25 Last Chance

Conversion of Qvector<qreal> to QVariant fails

Scheduled Pinned Locked Moved Unsolved General and Desktop
qvariantqvectorqmap
7 Posts 3 Posters 637 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.
  • S Offline
    S Offline
    sayan275
    wrote on 22 Jul 2024, 06:54 last edited by
    #1

    Why is this conversion from QVector<qreal> to QVariant fails?? same code is working in othermodule while reading values from json and filling in the same type of data structure
    f6a797d7-c8d4-440b-92f7-79ce3c33b60c-image.png

    Other Module, where it conversion is fine
    a29545c9-8a7f-4ec5-8527-89fed28a299b-image.png

    Any suggestions, what am I missing?

    J P 2 Replies Last reply 22 Jul 2024, 07:11
    0
    • S sayan275
      22 Jul 2024, 06:54

      Why is this conversion from QVector<qreal> to QVariant fails?? same code is working in othermodule while reading values from json and filling in the same type of data structure
      f6a797d7-c8d4-440b-92f7-79ce3c33b60c-image.png

      Other Module, where it conversion is fine
      a29545c9-8a7f-4ec5-8527-89fed28a299b-image.png

      Any suggestions, what am I missing?

      J Offline
      J Offline
      JonB
      wrote on 22 Jul 2024, 07:11 last edited by
      #2

      @sayan275
      I suggest you put in some code (e.g. suitable qDebug()) to show the result from QVariant::fromValue(), and maybe what is in points, rather than relying on interpreting what is shown in the debugger window.

      S 1 Reply Last reply 22 Jul 2024, 08:39
      0
      • J JonB
        22 Jul 2024, 07:11

        @sayan275
        I suggest you put in some code (e.g. suitable qDebug()) to show the result from QVariant::fromValue(), and maybe what is in points, rather than relying on interpreting what is shown in the debugger window.

        S Offline
        S Offline
        sayan275
        wrote on 22 Jul 2024, 08:39 last edited by
        #3

        @JonB 9fe99f10-e36b-4e76-943d-a24a2952cc5c-image.png

        AnnotationViewerPlugins::RadarChartConfig::on_chartUpdatePBtn_clicked "FRONTLeft_inner_area_yMax"   4.5
        AnnotationViewerPlugins::RadarChartConfig::on_chartUpdatePBtn_clicked "FRONTLeft_inner_area_xMin"   4.31
        AnnotationViewerPlugins::RadarChartConfig::on_chartUpdatePBtn_clicked "FRONTLeft_inner_area_xMax"   1.81
        AnnotationViewerPlugins::RadarChartConfig::on_chartUpdatePBtn_clicked points vec:: QVector(-1.75, 4.5, 4.31, 1.81)
        AnnotationViewerPlugins::RadarChartConfig::on_chartUpdatePBtn_clicked pt Variant:: QVariant(QVector<double>, )
        
        1 Reply Last reply
        0
        • J Offline
          J Offline
          JonB
          wrote on 22 Jul 2024, 08:55 last edited by JonB
          #4

          AnnotationViewerPlugins::RadarChartConfig::on_chartUpdatePBtn_clicked pt Variant:: QVariant(QVector<double>, )

          So far as I can tell, all that shows is that the result is of type QVariant(QVector<double>, ). (Don't know what the significance is of the trailing comma, if any.)

          I expected you print out the lengths/values, to see what is going on. Anyway, doesn't the code in the solution at https://stackoverflow.com/questions/40437335/converting-qvariant-to-qvectorint show you what you should be doing? Sorry, that was the wrong way round, it does QVariant to QVector.

          S 1 Reply Last reply 22 Jul 2024, 09:15
          0
          • J JonB
            22 Jul 2024, 08:55

            AnnotationViewerPlugins::RadarChartConfig::on_chartUpdatePBtn_clicked pt Variant:: QVariant(QVector<double>, )

            So far as I can tell, all that shows is that the result is of type QVariant(QVector<double>, ). (Don't know what the significance is of the trailing comma, if any.)

            I expected you print out the lengths/values, to see what is going on. Anyway, doesn't the code in the solution at https://stackoverflow.com/questions/40437335/converting-qvariant-to-qvectorint show you what you should be doing? Sorry, that was the wrong way round, it does QVariant to QVector.

            S Offline
            S Offline
            sayan275
            wrote on 22 Jul 2024, 09:15 last edited by
            #5

            @JonB it's (type, value), since value is empty, there is nothing after ,

            penVart:: QVariant(int, 2)
            
            J 1 Reply Last reply 22 Jul 2024, 10:18
            0
            • S sayan275
              22 Jul 2024, 09:15

              @JonB it's (type, value), since value is empty, there is nothing after ,

              penVart:: QVariant(int, 2)
              
              J Offline
              J Offline
              JonB
              wrote on 22 Jul 2024, 10:18 last edited by JonB
              #6

              @sayan275
              I should have been a lot happier if you extracted the vector from the variant and showed, say, its length rather than relying on the interpretation of how qDebug() displays a variant overall. I trust you are correct.

              I agree I am not sure, and I don't know why you seem to show it working in one place and not in another. Why don't you start by temporarily making them integers and testing same code with QVariant<int> instead of QVariant<qreal> so we can eliminate some qreal issue?

              1 Reply Last reply
              0
              • S sayan275
                22 Jul 2024, 06:54

                Why is this conversion from QVector<qreal> to QVariant fails?? same code is working in othermodule while reading values from json and filling in the same type of data structure
                f6a797d7-c8d4-440b-92f7-79ce3c33b60c-image.png

                Other Module, where it conversion is fine
                a29545c9-8a7f-4ec5-8527-89fed28a299b-image.png

                Any suggestions, what am I missing?

                P Offline
                P Offline
                Pl45m4
                wrote on 22 Jul 2024, 12:15 last edited by
                #7

                @sayan275

                It's also always better to post the relevant code as text and not as image, so others can reproduce it easier.


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                1 Reply Last reply
                3

                5/7

                22 Jul 2024, 09:15

                • Login

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