How to fix "This file is not part of any project. The code model might have issues parsing this file properly." bug in Qt Creator? - c++

I just installed Qt creator (for the 10th time probably), and even when I follow the simple steps to create a new Qt Widget or Qt Console applications, I get this error. Extremely frustrated with various Qt Creator bugs. Help will be appreciate.

If you look closely at your workspace, you can see, that there are two projects. One project is called Sample, one project is called Widget. The active project is "Sample". You can tell that from the project browser as the Sample project is in bold letters. So building and debugging applies only to the Sample project.
The open file where you set your breakpoints in is "Widget/main.cpp", it belongs to the other non-active "Widget" project. So when you start the debugger, the environment warns you that this will not work. Completely correct behaviour.

Maybe try the following:
1- Ensure case sensitive typing of the file name and type the full path not just the name.
2- Delete configuration files that are automatically created.
3- Make sure the QT environment is setup correctly pointing to the required compilers, packages and resources.
4- Check if there are any missing environment variables on your machine.

The problem could be in the .pro
Check that you have the file into the source in the .pro

Related

NSCameraUsageDescription needed for C++ projects in Xcode for MacOS Mojave

I am trying to run OpenCV projects in Xcode and it seems like there's a new need to provide an info.plist for C++ applications NSCameraUsageDescription.
2018-09-28 00:03:15.181948+0800 k_nearest_detector_v2[23505:710470] [access] This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data.
Program ended with exit code: 9
How do I go about creating a .plist file for a C++ project as it has never been needed before.
Found a solution. Put the file with the desired NSCameraUsageDescription, NSMicrophoneUsageDescription (or others) with the assembled file from XCode (See screen shots below). For the Release and Debug versions.
You can even automate the steps described by #Valery Gromov. Just copy the file in the Build Phases. Uncheck the Copy only when installing checkbox to be able to run it directly from Xcode.

How do I turn my C++ code into a .app file? [duplicate]

I am building a C++ OpenGL card game in Xcode 4.3.3, with the intention of running it on both 64-bit and 32-bit Macs, which is not my problem. My problem is that I have reached a point in the development of the program where I would like to test that it works on a different 32-bit Mac (mine is 64-bit) without having to install Xcode. This, obviously, requires me exporting it as an .app. I can find and run the exported Unix Executable File from my project, after some cd'ing, through Terminal, but that is undesirable for me and the intended audience of the program. I have trawled the google and Stack Overflow, looking for anything to help me, but all the things mentioning Archiving seem to have been unsuccessful with my particular project, and I think that's because it's a C++ command line tool project. So, can someone please help me export my project as a .app?
Thanks in advance.
The simplest way of doing this would be to create a Cocoa project, go to 'build phases' and remove all the objective-c frameworks from the 'link with libraries' build phase, remove any objective-c files added by the template (app delegate, etc.) and then replace main.c with your main.cpp file.
There's nothing really special about a Cocoa project except for the fact that it links against Cocoa and calls NSApplicationMain() from its main() function.
There are also a bunch of .plist entries used by Cocoa which you'll no longer need. But they won't affect the way OS X treats your application.
I'm searching for an XCode Settings solution but here's my current way to create an app:
You have to take your binary file (let say myapp) and put it in "MyApp.app/Contents/MacOS/myapp" then it can now be launched as a .app. That's a trick.
Just go to the targets folder in the file navigator on the left, and there will be an executable listed there. Left click on that executable and click "show in finder". (I'm describing from memory so I may have the exact details wrong.) The file path is ridiculously long (there is an arbitrary alphanumerical pathname involved, I have no idea why), so you probably won't be able to find it with the command line.
If you want you can change the extension of the file from nothing to ".app", it shouldn't affect the nature of the file at all. Also if you want a custom icon, you can "get info" on it in the finder, then click on the icon in the info window, and use Cmd-V to paste it in (obviously you have to have your icon copied to the clipboard). There is also a way to do this inside of Xcode, but I don't remember it.

can't include Qt classes while creating project with VS-add in

I recently begin to use Qt and decided to use it with Visual Studio (2013).
The problem is that when i create the project the Qt classes even the most common can't be included (as QApplication) even if i had to it every Modules (core GUI...). Intellisense underline it in red saying :"cannot open source file QApplication". And when i try to run the project, it tells me that i missed some .dll. The weirdest thing is that i already manage (2 times) to make it worked, simply by creating the project without doing anything special(i think).
Moreover when i use the qtcreator it works fine but i'd like to use VS.
Sorry, i had a hard time being specific since i really don't have a clue.
In addition #drescherjm comment, you should also check that you have an system environment variable set - The variable name should be QTDIR and the path should be the path of your installation - on my system this is C:\Qt\Qt5.5.1\5.5\msvc2013.
OK, it seems i found a way to resolve the problem but i still don't get why.
It appears that if i go in the Qt options even if the path is already set, i need to select it and press ok. And then build the project and reopen it for intelisense to work. And it worked. But it's weird because i already fund the place where the qtdir variable is stored and it was alright but the project still didn't worked??

Run time error on executing the exe manually

I have a Qt application, which runs fine when I execute it from Qt Creator. However, on running it by manually clicking the generated exe, I get the following error :
I would understand if it would ask for missing DDLs (which I could then place in the same folder). But how should I proceed to handle this (in general) ?
P.S. It is not giving any line number in my source code which I could try testing this assert for. I tried using the release mode as well, but the same error.
We don't know what the problem with your code is; you'll need to use a debugger to find that out. I think that the pre-built Qt libraries that you download come with debug symbols, but if they don't, you can always build Qt yourself to get them using the -force-debug-info configure option.
You can also use DebugView to see debug output of deployed applications.
However, in general, you should use the windeployqt tool that is included with Qt.
The Qt for Windows - Deployment page has more information about deploying Qt applications to Windows machines, but windeployqt should do everything you need.
My qml files were not getting deployed properly and thus this error (this assert is probably on the variable storing the main qml file name, i.e. it should not be an empty string, which in case of missing main.qml, it was). Placing the qml files at correct paths solved the issue.
Also, as #mitch has pointed out in his answer, use windeployqt to find out the dependencies. Although, I have also realized that it doesn't cover all the dependencies (MSVC runtimes for example and other compiler related files sometimes). In that case run the dependency walker and place the missing files manually along with the exe.

VS2013 debugger can no longer resolve system environment variable containing source code path

I am currently using Visual Studio 2013 (Update 4) for building Qt5.4.0 projects. I use the express version so I don't use the VS plugin. My .vcxproj files a generated from .pro files using build scripts and qmake.
When debugging my projects I sometimes try to step into Qt library code. To do this I added the path to the Qt source codes to the solution properties->Debug Source Files setting like described in a former post (VS2013 debugger can not find Qt sources).
Because I have many different projects and it would be a pain to update all of them in case of a Qt update I used a system environment variable "QTSRC" pointing to that path and added the following line to the solution:
$(QTSRC)
This worked like charm some time ago (with an older update of VS and a former Qt version 5.x).
But unfortunately it does not work anymore. It seems that VS now totally ignores the system environment variable (it also does not show any errors when I check the "check entries" button in the dialog).
Does anybody know what changed here lately and what must be done to fix this? It would be very annoying to add the path hardcoded to every project (which still works) and have to do this over and over again after Qt updates.
I'd look at the Property Pages which will allow you to set user defined values that you can share across different projects:
http://msdn.microsoft.com/en-us/library/675f1588.aspx
I use them to set global include paths, but it looks like you can set almost anything there. Set things in the .User pages if you want them used for all your projects but not included in the solution or project file itself.
A good, short, guide is here:
http://www.curlybrace.com/words/2012/12/17/setting-global-c-include-paths-in-visual-studio-2012-and-2011-and-2010/