Remove console from waf build Qt Program on Windows

I have this Qt program that I create with waf . I test it on Windows and every time I run an exe file the console opens. In the (Qt) pro file (if you are building with qmake) you just need to make sure you delete

CONFIG += console

But I'm not sure which linker flag I should add to my wscript (waf) for this to happen. I need to specify /SUBSYSTEM: WINDOWSfor msvc-complier to take my program as a window program

Please, help.

my wscript.py

#! /usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2005, 2011 (ita)
"""
Including the moc files *is* the best practice (KDE), not doing it is easy,
but makes the compilations about 30-40% slower on average.
If you still want the slow version (we warned you!), see the example located
in the folder playground/slow_qt/
"""
VERSION='0.0.1'
APPNAME='qt4_test'
top = '.'
out = 'build'
def options(opt): 
    opt.load('compiler_cxx qt4 compiler_c boost')
def configure(conf):
    conf.load('compiler_cxx qt4 compiler_c boost')
    #if conf.env.COMPILER_CXX == 'msvc': g++
    #conf.check_tool('boost')
    conf.env.append_value('CXXFLAGS', ['-DWAF=1']) # test
    #conf.env.append_value('DWAF','1')
    #conf.recurse(subdirs)
    #conf.check_cc( ccflags='-mwindows', mandatory=True, msg='Checking for flags -mwindows')
def build(bld):
    cxxflags = bld.env.commonCxxFlags
    uselibcommon = 'QTCORE QTGUI QTOPENGL QTSVG QWIDGET QTSQL QTUITOOLS QTSCRIPT'
    bld(features = 'qt4 cxx',  includes = '.',source   = 'ListModel.cpp', target = 'ListModel.o', uselib = uselibcommon, cxxflags=cxxflags)
    bld(features = 'qt4 cxx',  includes = '.', source   = 'Model.cpp', target = 'Model.o', uselib = uselibcommon,  cxxflags=cxxflags)
    bld(features = 'qt4 cxx',  includes = '.', source = 'ProxyModel.cpp' , target = 'ProxyModel.o', uselib = uselibcommon, cxxflags=cxxflags)
    flags = cxxflags + ['-DWAF']
    bld(features = 'qt4 cxx',  includes = bld.options.boost_includes, source = 'TableModel.cpp', target = 'TableModel.o', uselib = uselibcommon, cxxflags=flags)
    bld(features = 'qt4 cxx',  includes = '.', source   = 'SongItem.cpp', target = 'SongItem.o',use = 'ListModel.o',  cxxflags=cxxflags)

    use = [ 'sqlite3.o', 'Master.o' , 'DatabaseUtil' , 'SQLiteError.o' ,  'Vector.o' , 'Song.o' , 'Songs.o' , 'SQLiteVector.o' , 'SQLiteVectorIterator.o' , 'ListModel.o' , 'Model.o' , 'TableModel.o' , 'SongItem.o'  ,  'ProxyModel.o']
    bld(features = 'qt4 cxx c', uselib = uselibcommon, includes = bld.options.boost_includes , source   = 'MainWindow.cpp' , target = 'MainWindow.o', lib = ['phonon'], libpath = ['/usr/lib'], use = use, cxxflags=cxxflags)

    use = [ 'sqlite3.o', 'Master.o' , 'DatabaseUtil' , 'SQLiteError.o' ,  'Vector.o' , 'Song.o' , 'Songs.o' , 'SQLiteVector.o' , 'SQLiteVectorIterator.o' , 'ListModel.o' , 'Model.o' , 'TableModel.o' , 'SongItem.o'  , 'ProxyModel.o',
    'MainWindow.o']
    bld(features = 'qt4 cxx cxxprogram', includes = bld.options.boost_includes, source = 'main.cpp MasterDetail.qrc', target   = 'app', uselib = uselibcommon , cxxflags=cxxflags, use = use, linkflags = (['-Wl,-subsystem,windows']) )

from waflib.TaskGen import feature, before_method, after_method
@feature('cxx')
@after_method('.')
@before_method('apply_incpaths')
def add_includes_paths(self):
        incs = set(self.to_list(getattr(self, 'includes', '')))
        for x in self.compiled_tasks:
                incs.add(x.inputs[0].parent.path_from(self.path))
        self.includes = list(incs)
+3
source share
3 answers

I got a solution

in windows, use (mingw)

linkflags = ['-Wl,-subsystem,windows'], -> to disable the console
linkflags = ['-Wl,-subsystem,console'], -> to enable the console

use (msvc)

subsystem='windows', -> to disable the console
subsystem='console', -> to enable the console
+2
source

I think you need / SUBSYSTEM: WINDOWS, not / SUBSYSTEM = WINDOWS.

0

As soon as I used the hacker method - when the application, depending on the command line flags, was supposed to behave as a console application or as a user interface application (without a console). He fell down (under Windows) to create it as a console application and got rid of the console if certain conditions were met:

#include <windows.h>

if(getRidOfTheConsole)
    FreeConsole();

An alternative (already known to you) is to use /SUBSYSTEM:WINDOWS. I do not know how to put it in waf, but there is another way: add the following to your file int main()::

#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
0
source

All Articles