Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::cout doesn't print anything in console #35

Closed
kahlenberg opened this issue Apr 24, 2024 · 8 comments
Closed

std::cout doesn't print anything in console #35

kahlenberg opened this issue Apr 24, 2024 · 8 comments

Comments

@kahlenberg
Copy link

kahlenberg commented Apr 24, 2024

I am starting one of the examples, vsgtviewer from the console, for testing purposes I added std::cout << "test" << std::endl; in the first line of the main function. But it doesn't print anything. Even if I don't give any model as parameter it doesn't show the error
std::cout << "Please specify a 3d model or image file on the command line." at line 108.
How can I print something in the console?

@robertosfield
Copy link
Collaborator

I haven't heard of others having issues with using std::cout. I personally use it all the time without problems.

Is this just vsgqtviewer or do non Qt VSG examples like vsgviewer from vsgExamples do this on your system as well?

What OS. VSG and Qt versions are you using?

@kahlenberg
Copy link
Author

kahlenberg commented Apr 25, 2024

Sorry, I didn't give enough information:
Windows 10 64 bit, Vulkan SDK 1.3.275.0, VSG 1.1.2, Qt Version: 5.12.7.
I am getting this problem in all 3 examples, vsqtmdi, vsqtviewer, vsgtwindows. Release and Debug configs.
When I enter the program name (vsqtviewer.exe models/openstreetmap.vsgt for example), it immediately returns to console again, after 1-2 seconds window appears.

image

@robertosfield
Copy link
Collaborator

I'll have been running vsgQt based application under WIndows 11 for the last couple of months without issues so I don't think there is a general problem. I will test writing to the console to see what happens.

What hardware are you using?

Have you tried standard vsgExamples like vsgviewer?

Could you run the examples with the -d option to enable the Vulkan Validation Layer to see if you system is producing errors.

@kahlenberg
Copy link
Author

kahlenberg commented Apr 25, 2024

vsgviewer in vsgExamples works as expected, It prints std::cout text, I enabled -d option but it doesn't print any debug information. The flag -a prints a lot of information.
But in vsgQt, flags (-d, -a) don't work (it doesn't show anything).
I am using DELL Latitude 5501 laptop with NVIDIA GeForce MX150.

@robertosfield
Copy link
Collaborator

I have tried things out on Windows 11 and find the same problem - std::cout and any vsg::info() etc. calls are eaten by Qt.

I searched on the web and came across lots of others having this problem. I can only presume that Qt is overriding the standard library's console output. Fixing Qt issues really isn't the responsibility of VSG/vsgQt so I'll have to recommend you go research what Qt is doing directly with the Qt community.

As an aside, I recently had to implement a redirect of std::cout/std::cerr in the vsg::Logger but applications have to explicitly call vsg::Loggerin::instance()->redirect_std(); This was merged with this VSG PR:

vsg-dev/VulkanSceneGraph#1161

Potentially you could write a custom vsg::Logger to redirect it's output to Qt logging or other logging capabilities. The later is what a client does on a Windows/Qt/VSG application. The vsg::Logger::redirect_std() was required to capture the Vulkan API Layer that only writes to std::cout.

I am closing this Issue as it's a Qt issue and needs to be taken up with the Qt community.

@kahlenberg
Copy link
Author

Ok, thank you very much for your time and testing!

@kahlenberg
Copy link
Author

Just solved my problem, I post here for future references:

In Visual Studio, I changed the properties of the project.
Properties -> Linker -> System -> SubSystem was set to Windows (/SUBSYSTEM:WINDOWS), I set it to Console (/SUBSYSTEM:CONSOLE). It prints cout to the console now.
Windows (/SUBSYSTEM:WINDOWS) expects WinMain() instead of main().

@robertosfield
Copy link
Collaborator

I presume Qt or it's CMake support is setting this, it's not something I've set previously, but then I'm 99% unix based so have to defer to Windows dev for guidance on how best to work it's idiosyncrasies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants