简体   繁体   中英

Why i can't use console output in QBS project?

In my qbs file:

import qbs

Project {
    name: {
            console.info("Hello!");
            return "ProjectName";
    }
 ...
 }

I've got message: ReferenceError: Can't find variable: console

My Qt version is 5.5.0. My Qt Creator version is 3.5.1

I've use binaries from MSYS2 repo.

EDIT: I can see methods of console variable in text editor by Ctrl-Space hotkey.

The console logging API is supported in Qbs 1.5 and its output will show up in Qt Creator's General Messages tab. In Qbs 1.4.5 and below, print() is the only debugging function available. As the other answer shows, you'll have to use that or throw .

A release date for Qbs 1.5 has not yet been set. Qbs 1.5 was released Wednesday the 11th of May 2016.

While I'm not sure why console object isn't supported in qbs (still stuck in qmake land myself), you can get console output with print :

        print("Hello!");

This works in console, but not in Qt Creator, yet. This will be resolved in qbs 1.5, but it isn't released yet at the time of writing this, as pointed out by @JakePetroules. The relevant, resolved bug report is here .

For older versions, it seems you just have to either throw "Hello!"; (which makes the build fail), or run qbs from command line when debugging the project building (the used command can be conveniently copied from Qt Creator Projects view).


As to why Qt Creator autocompletion shows it, it'll hazard a guess: it might because console is hard-coded into its Javascript auto-completion as a core Javascript feature which is always available. Might be worth writing a bug report !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM