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. returning empty std::string when converting a QString with a path to an std::string using toStdString
Forum Updated to NodeBB v4.3 + New Features

returning empty std::string when converting a QString with a path to an std::string using toStdString

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 4 Posters 1.3k 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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Please don't pictures but text - so we can try out the code directly.

    You forgot to flush the output buffer -> see std::endl or std::flush

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

    U 2 Replies Last reply
    2
    • Christian EhrlicherC Christian Ehrlicher

      Please don't pictures but text - so we can try out the code directly.

      You forgot to flush the output buffer -> see std::endl or std::flush

      U Offline
      U Offline
      UbiMiles
      wrote on last edited by
      #3

      @Christian-Ehrlicher the text is recieved from QML from a FolderDialog
      then converted from URL to QString

      Christian EhrlicherC 1 Reply Last reply
      0
      • U UbiMiles

        @Christian-Ehrlicher the text is recieved from QML from a FolderDialog
        then converted from URL to QString

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @UbiMiles Did you actually read my answer on why it does not print something?

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

        1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          Please don't pictures but text - so we can try out the code directly.

          You forgot to flush the output buffer -> see std::endl or std::flush

          U Offline
          U Offline
          UbiMiles
          wrote on last edited by
          #5

          @Christian-Ehrlicher as for flushing I am not intending to output the string but using it with an external SDK, the bug caused a weird exception in the disassembler
          and I found out it is because the string is empty

          Christian EhrlicherC U 2 Replies Last reply
          0
          • U UbiMiles

            @Christian-Ehrlicher as for flushing I am not intending to output the string but using it with an external SDK, the bug caused a weird exception in the disassembler
            and I found out it is because the string is empty

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @UbiMiles The string is not empty. Please provide a minimal, compilable example of your real code. Your code above does not output anything because (third time) you forgot to flush the output buffer.

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

            U 1 Reply Last reply
            0
            • U UbiMiles

              @Christian-Ehrlicher as for flushing I am not intending to output the string but using it with an external SDK, the bug caused a weird exception in the disassembler
              and I found out it is because the string is empty

              U Offline
              U Offline
              UbiMiles
              wrote on last edited by
              #7

              @UbiMiles oh
              I do see now , my bad.. pardons

              1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @UbiMiles The string is not empty. Please provide a minimal, compilable example of your real code. Your code above does not output anything because (third time) you forgot to flush the output buffer.

                U Offline
                U Offline
                UbiMiles
                wrote on last edited by
                #8

                @Christian-Ehrlicher
                when passing the standard library string to a function it causes a runtime error in the disassembler
                do you have any idea what may be causing such issue

                Christian EhrlicherC 1 Reply Last reply
                0
                • U UbiMiles

                  @Christian-Ehrlicher
                  when passing the standard library string to a function it causes a runtime error in the disassembler
                  do you have any idea what may be causing such issue

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @UbiMiles said in returning empty std::string when converting a QString with a path to an std::string using toStdString:

                  when passing the standard library string to a function it causes a runtime error in the disassembler

                  Maybe you mix debug and release dlls which you're not allowed to do so on Windows.
                  No more ideas without any code / minimal compilable example.

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

                  U 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    @UbiMiles said in returning empty std::string when converting a QString with a path to an std::string using toStdString:

                    when passing the standard library string to a function it causes a runtime error in the disassembler

                    Maybe you mix debug and release dlls which you're not allowed to do so on Windows.
                    No more ideas without any code / minimal compilable example.

                    U Offline
                    U Offline
                    UbiMiles
                    wrote on last edited by
                    #10

                    @Christian-Ehrlicher
                    I think the porblem has to do with me appending the date and time to my string

                        sampleName.append(QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss"));
                    
                    
                    U J.HilkJ 2 Replies Last reply
                    0
                    • U UbiMiles

                      @Christian-Ehrlicher
                      I think the porblem has to do with me appending the date and time to my string

                          sampleName.append(QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss"));
                      
                      
                      U Offline
                      U Offline
                      UbiMiles
                      wrote on last edited by
                      #11

                      @UbiMiles yes
                      testing without appending the date and time works just fine without any crashes

                      1 Reply Last reply
                      0
                      • U UbiMiles

                        @Christian-Ehrlicher
                        I think the porblem has to do with me appending the date and time to my string

                            sampleName.append(QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss"));
                        
                        
                        J.HilkJ Offline
                        J.HilkJ Offline
                        J.Hilk
                        Moderators
                        wrote on last edited by J.Hilk
                        #12

                        @UbiMiles said in returning empty std::string when converting a QString with a path to an std::string using toStdString:

                        @Christian-Ehrlicher
                        I think the porblem has to do with me appending the date and time to my string

                            sampleName.append(QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss"));
                        
                        

                        on windows, a colon (:)is not a valid character for filenames and/or a path


                        annotation, : can and in fact is part of every windows (full) path, but its reserved for the drive letter association


                        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                        Q: What's that?
                        A: It's blue light.
                        Q: What does it do?
                        A: It turns blue.

                        U 1 Reply Last reply
                        5
                        • J.HilkJ J.Hilk

                          @UbiMiles said in returning empty std::string when converting a QString with a path to an std::string using toStdString:

                          @Christian-Ehrlicher
                          I think the porblem has to do with me appending the date and time to my string

                              sampleName.append(QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss"));
                          
                          

                          on windows, a colon (:)is not a valid character for filenames and/or a path


                          annotation, : can and in fact is part of every windows (full) path, but its reserved for the drive letter association

                          U Offline
                          U Offline
                          UbiMiles
                          wrote on last edited by
                          #13

                          @J-Hilk said in returning empty std::string when converting a QString with a path to an std::string using toStdString:

                          sampleName.append(QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss"));
                          

                          thanks a lot, much appreciated sir.

                          1 Reply Last reply
                          0
                          • U UbiMiles

                            input :
                            2d923a1f-00dc-4b77-8538-d4c338f3030a-image.png

                            output:
                            4d91feb7-645e-40ba-8432-5411f9852ec4-image.png

                            is it because of the backslash?
                            how can I possibly fix this behavior

                            S Offline
                            S Offline
                            Spade
                            wrote on last edited by
                            #14
                            This post is deleted!
                            1 Reply Last reply
                            0

                            • Login

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