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. how to print a file url using qDebug or other api to locate file in qtcreator?
Forum Updated to NodeBB v4.3 + New Features

how to print a file url using qDebug or other api to locate file in qtcreator?

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 4 Posters 806 Views 1 Watching
  • 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.
  • Q Offline
    Q Offline
    QtTester
    wrote on 16 Nov 2021, 06:17 last edited by QtTester
    #1

    Hi ,guys.
    Usually i use

    qDebug() <<"my log:"<<__FILE__;
    

    to output log.
    But suddently I found qt core lib can print the file url and click the url qtcreator will locate the file. you can see the following image:

    alt text

    So how to do that?

    J J 2 Replies Last reply 16 Nov 2021, 06:22
    0
    • Q QtTester
      16 Nov 2021, 06:17

      Hi ,guys.
      Usually i use

      qDebug() <<"my log:"<<__FILE__;
      

      to output log.
      But suddently I found qt core lib can print the file url and click the url qtcreator will locate the file. you can see the following image:

      alt text

      So how to do that?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 16 Nov 2021, 06:22 last edited by
      #2

      @QtTester said in how to print a file url using qDebug or other api to locate file in qtcreator?:

      But suddently I found qt core lib can print the file url and click the url qtcreator will locate the file.

      I really fail to understand what you're writing!
      Can you please explain better?

      qDebug() << url;
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      Q 1 Reply Last reply 16 Nov 2021, 06:27
      0
      • J jsulm
        16 Nov 2021, 06:22

        @QtTester said in how to print a file url using qDebug or other api to locate file in qtcreator?:

        But suddently I found qt core lib can print the file url and click the url qtcreator will locate the file.

        I really fail to understand what you're writing!
        Can you please explain better?

        qDebug() << url;
        
        Q Offline
        Q Offline
        QtTester
        wrote on 16 Nov 2021, 06:27 last edited by
        #3

        @jsulm
        well, when using:

        qDebug() << __FILE__;
        

        we see the output looks like this:

        ..\..\..\..\Common\common\CommonLib\pluginmanager.cpp
        

        but ,we cannot click the text !!!
        in above image, the text

        ..\..\MotionControlApp\motioncontrolapp.cpp:1337
        

        is like a http url, we can click and jump to the file & line!
        How can i achieve this?

        J 1 Reply Last reply 16 Nov 2021, 06:29
        0
        • Q QtTester
          16 Nov 2021, 06:27

          @jsulm
          well, when using:

          qDebug() << __FILE__;
          

          we see the output looks like this:

          ..\..\..\..\Common\common\CommonLib\pluginmanager.cpp
          

          but ,we cannot click the text !!!
          in above image, the text

          ..\..\MotionControlApp\motioncontrolapp.cpp:1337
          

          is like a http url, we can click and jump to the file & line!
          How can i achieve this?

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 16 Nov 2021, 06:29 last edited by
          #4

          @QtTester said in how to print a file url using qDebug or other api to locate file in qtcreator?:

          but ,we cannot click the text !!!

          Click where?
          qDebug outputs the text at runtime in the console, I don't know what you want to click and where...

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          Q 1 Reply Last reply 16 Nov 2021, 06:41
          0
          • J jsulm
            16 Nov 2021, 06:29

            @QtTester said in how to print a file url using qDebug or other api to locate file in qtcreator?:

            but ,we cannot click the text !!!

            Click where?
            qDebug outputs the text at runtime in the console, I don't know what you want to click and where...

            Q Offline
            Q Offline
            QtTester
            wrote on 16 Nov 2021, 06:41 last edited by QtTester
            #5

            @jsulm
            can you see my image? url is in the red circle.
            Text:
            ........\Common\common\CommonLib\myfile.cpp
            is printed as (for example):
            <a href="c:\myfile.cpp">........\Common\common\CommonLib\myfile.cpp</a>
            it can be clicked!
            do you use android studio? AS also can print file url and you can quickly click to locate the file.

            J 1 Reply Last reply 16 Nov 2021, 06:44
            0
            • Q QtTester
              16 Nov 2021, 06:41

              @jsulm
              can you see my image? url is in the red circle.
              Text:
              ........\Common\common\CommonLib\myfile.cpp
              is printed as (for example):
              <a href="c:\myfile.cpp">........\Common\common\CommonLib\myfile.cpp</a>
              it can be clicked!
              do you use android studio? AS also can print file url and you can quickly click to locate the file.

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 16 Nov 2021, 06:44 last edited by jsulm
              #6

              @QtTester said in how to print a file url using qDebug or other api to locate file in qtcreator?:

              can you see my image?

              No, I can't - it doesn't open.
              If I understand you correctly this has nothing to do with qDebug(). You want to click on __FILE__ in QtCreator, right? But what should happen then? __FILE__ is the path of the source code file where you put it, but that file is already open (else you would not be able to click on it). So, what should happen?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              Q 1 Reply Last reply 16 Nov 2021, 06:57
              0
              • J jsulm
                16 Nov 2021, 06:44

                @QtTester said in how to print a file url using qDebug or other api to locate file in qtcreator?:

                can you see my image?

                No, I can't - it doesn't open.
                If I understand you correctly this has nothing to do with qDebug(). You want to click on __FILE__ in QtCreator, right? But what should happen then? __FILE__ is the path of the source code file where you put it, but that file is already open (else you would not be able to click on it). So, what should happen?

                Q Offline
                Q Offline
                QtTester
                wrote on 16 Nov 2021, 06:57 last edited by QtTester
                #7

                @jsulm
                You are right.
                another image url if you can see it: https://ibb.co/4dTqKQc
                If we can click the file and line.
                QtCreator can quickly open the file and locate to the exactly line!
                That will be much more help to us to debug!
                only using FILE may be not the right choice. I am wondering how to do this.

                J 1 Reply Last reply 16 Nov 2021, 07:47
                0
                • Q QtTester
                  16 Nov 2021, 06:57

                  @jsulm
                  You are right.
                  another image url if you can see it: https://ibb.co/4dTqKQc
                  If we can click the file and line.
                  QtCreator can quickly open the file and locate to the exactly line!
                  That will be much more help to us to debug!
                  only using FILE may be not the right choice. I am wondering how to do this.

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 16 Nov 2021, 07:47 last edited by
                  #8

                  @QtTester said in how to print a file url using qDebug or other api to locate file in qtcreator?:

                  QtCreator can quickly open the file and locate to the exactly line!

                  But it already does? I still don't understand what you want to do!
                  Again: where and when do you want to click?
                  During debugging in debugger?
                  Or do you want to click in Application Output tab in QtCreator?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • Q QtTester
                    16 Nov 2021, 06:17

                    Hi ,guys.
                    Usually i use

                    qDebug() <<"my log:"<<__FILE__;
                    

                    to output log.
                    But suddently I found qt core lib can print the file url and click the url qtcreator will locate the file. you can see the following image:

                    alt text

                    So how to do that?

                    J Online
                    J Online
                    J.Hilk
                    Moderators
                    wrote on 16 Nov 2021, 08:22 last edited by
                    #9

                    @QtTester looking at the patch when this was added:

                    https://codereview.qt-project.org/c/qt-creator/qt-creator/+/251919

                    I would say,

                    qDebug().nospace() << "file://"<< __FILE__ << ":" << __LINE__;
                    

                    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.

                    Q 2 Replies Last reply 17 Nov 2021, 01:34
                    3
                    • M Offline
                      M Offline
                      mchinand
                      wrote on 16 Nov 2021, 14:14 last edited by
                      #10

                      Switch to the newer QObject::connect syntax and you will get an error at compile-time instead of run-time for the error you are seeing in your first screenshot. You will likely get more detailed info to help you fix your error. You probably have to qobject_cast() your obj to the correct class instead of just to a QObject.

                      1 Reply Last reply
                      1
                      • J J.Hilk
                        16 Nov 2021, 08:22

                        @QtTester looking at the patch when this was added:

                        https://codereview.qt-project.org/c/qt-creator/qt-creator/+/251919

                        I would say,

                        qDebug().nospace() << "file://"<< __FILE__ << ":" << __LINE__;
                        
                        Q Offline
                        Q Offline
                        QtTester
                        wrote on 17 Nov 2021, 01:34 last edited by
                        #11

                        @J-Hilk said in how to print a file url using qDebug or other api to locate file in qtcreator?:

                        @QtTester looking at the patch when this was added:

                        https://codereview.qt-project.org/c/qt-creator/qt-creator/+/251919

                        I would say,

                        qDebug().nospace() << "file://"<< __FILE__ << ":" << __LINE__;
                        

                        that's exactly what I want !
                        Thank you!

                        1 Reply Last reply
                        1
                        • J J.Hilk
                          16 Nov 2021, 08:22

                          @QtTester looking at the patch when this was added:

                          https://codereview.qt-project.org/c/qt-creator/qt-creator/+/251919

                          I would say,

                          qDebug().nospace() << "file://"<< __FILE__ << ":" << __LINE__;
                          
                          Q Offline
                          Q Offline
                          QtTester
                          wrote on 17 Nov 2021, 06:19 last edited by
                          #12

                          @J-Hilk
                          Still having a little confusion , in the output panel, the text:

                          file://
                          

                          will also be displayed. like:

                          mylong:file://..\mainwindow.cpp:47,very good
                          

                          is there a way to hide "file://" ?

                          J 1 Reply Last reply 17 Nov 2021, 06:25
                          0
                          • Q QtTester
                            17 Nov 2021, 06:19

                            @J-Hilk
                            Still having a little confusion , in the output panel, the text:

                            file://
                            

                            will also be displayed. like:

                            mylong:file://..\mainwindow.cpp:47,very good
                            

                            is there a way to hide "file://" ?

                            J Online
                            J Online
                            J.Hilk
                            Moderators
                            wrote on 17 Nov 2021, 06:25 last edited by
                            #13

                            @QtTester to my knowledge file:// is mandatory to mark it as a file link

                            I don't know how you would hide it.


                            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.

                            1 Reply Last reply
                            0

                            1/13

                            16 Nov 2021, 06:17

                            • Login

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