Qmake quote function not actually putting quote



  • Hello,
    I am using this function (found on StaockOverflow) to copy files at the end of my build process

        defineTest(copyToDestDir) {
            files = $$1
    
            for(FILE, files) {
                DDIR = $$DESTDIR
    
                # Replace slashes in paths with backslashes for Windows
                win32:FILE ~= s,/,\\,g
                win32:DDIR ~= s,/,\\,g
    
                QMAKE_POST_LINK += $$QMAKE_COPY $$quote($$FILE) $$quote($$DDIR) $$escape_expand(\\n\\t)
            }
            export(QMAKE_POST_LINK)
        }
    

    The problem I have, is that the quote function does not put quote. In my compile output window I have :
    copy /y C:\Users\user101\Documents\WS\Qt\main\Host..\Libs\FTDI\x64* ..\Output\Debugx86_64

    => There is no quote

    And on another machine, the build path has a space in it, so it doesnt work at all.

    I have found this bug report : https://bugreports.qt.io/browse/QTBUG-44083 but it has been closed almost instantly because there is no bug.

    So what is the intended behavior of quote()?
    And How can qmake actually put quote so my copy works with space in it?


  • Moderators

    @Mwoua said in Qmake quote function not actually putting quote:

    defineTest(copyToDestDir) {
        files = $$1
    
        for(FILE, files) {
            DDIR = $$DESTDIR
    
            # Replace slashes in paths with backslashes for Windows
            win32:FILE ~= s,/,\\,g
            win32:DDIR ~= s,/,\\,g
    
            QMAKE_POST_LINK += $$QMAKE_COPY $$quote($$FILE) $$quote($$DDIR) $$escape_expand(\\n\\t)
        }
        export(QMAKE_POST_LINK)
    }
    

    change to

    defineTest(copyToDestDir) {
           files = $$1
    
           for(FILE, files) {
               DDIR = $$DESTDIR
    
               # Replace slashes in paths with backslashes for Windows
               win32:FILE ~= s,/,\\,g
               win32:DDIR ~= s,/,\\,g
    
               QMAKE_POST_LINK += $$QMAKE_COPY $$shell_quote($$FILE) $$shell_quote($$DDIR) $$escape_expand(\\n\\t)
           }
           export(QMAKE_POST_LINK)
       }
    

    basically you should use shell_quote instead of quote.

    That is what the comment in the bug report says.



  • Thats what I was trying, and it works, thanks.

    But what does quote function does?


  • Moderators

    @Mwoua

    The only thing I can offer are the comments in JIRA. It is not clear to me either.


  • Moderators

    Just playing a bit around brings this output

    FOOS = this is a string
    message("FOOS " $$FOOS)
    contains(FOOS, this is a string) {
    message("Does first contains ")
    }
    contains(FOOS, is) {
    message("Does second contains ")
    }
    message(" ")
    FOOS = "this is a string"
    message("FOOS " $$FOOS)
    contains(FOOS, this is a string) {
    message("Does first contains ")
    }
    contains(FOOS, is) {
    message("Does second contains ")
    }
    message(" ")
    
    FOOS = $$quote(this is a string)
    message("FOOS " $$FOOS)
    contains(FOOS, this is a string) {
    message("Does first contains ")
    }
    contains(FOOS, is) {
    message("Does second contains ")
    }
    message(" ")
    
    FOO = $$shell_quote(this is a string)
    message("FOO " $$FOO)
    FOO2 = $$system_quote(this is a string)
    message("FOO2 " $$FOO2)
    

    and the output is:

    Project MESSAGE: FOOS  this is a string
    Project MESSAGE: Does second contains 
    Project MESSAGE:  
    Project MESSAGE: FOOS  this is a string
    Project MESSAGE: Does first contains 
    Project MESSAGE:  
    Project MESSAGE: FOOS  this is a string
    Project MESSAGE: Does first contains 
    Project MESSAGE:  
    Project MESSAGE: FOO  "this is a string"
    Project MESSAGE: FOO2  "this is a string"
    

    Therefore, using the quote function is simply the same as putting a string into quotes. Assigning a string to a variable without quotes results into a string list. Only quotes or the quote function assigns a single string.

    In case also quotes have to be added to the variable one may use functions shell_quote or system_quote.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.