How to add LDFLAGS in qt .pro field?
consider Library folder and shared library(.so) is in a dir_path folder.
For example, adding this line is not solving the issue
LIBS+= -Ldir_path -llibrary_name
Any suggestions?
qmake has the QMAKE_LFLAGS variable for it.
You can read about qmake variables here.
Make sure that you use "TEMPLATE = app" to get the correct behavior. Using the "lib" template would ignore the LIBS variable.
use QMAKE_LDFLAGS for your requirement.
Related
I just installed Qt 5.15 and is testing how it works with opencv. I downloaded prebuild Opencv4.3, and set up a .pri file for being deployed in Qt.
The include and libs are as follows in the .pri file:
INCLUDEPATH += C:/opencv/opencv-4.3.0-prebuild/include
CONFIG(release, debug|release):{
LIBS += -LC:/opencv/opencv-4.3.0-prebuild/x64/vc14/lib \
-lopencv_world430
}
CONFIG(debug, debug|release):{
LIBS += -LC:/opencv/opencv-4.3.0-prebuild/x64/vc14/lib \
-lopencv_world430d
}
Then I run a simple image display domo:
#include "opencv2/opencv.hpp"
using namespace cv;
Mat img = imread("image.png");
if(img.empty())
{
qDebug()<<"Could not find the image";
}
else
{
namedWindow("Image");
imshow("Image", img);
}
The resulting error message: The program has unexpectedly finished. The process was ended forcefully.
Without linking with OpenCV, Qt itself works just fine.
What causes the problem?
It's not clear where is your example code is located. Is it in main?
Generally in OpenCV you also have an event loop (as in Qt) but it is hidden.
So if you want to actually see the namedWindow, you need to call cv::waitKey().
You can call it like cv::waitKey(1) if you do it periodically.
But generally you should do only the image processing in OpenCV, convert the cv::Mat to QImage, and show that in Qt.
I found this issue is due to an improper debugger set in the Qt Creator. Refer to the posts QtCreator no debugger set up (Windows). and Cannot run Qt example in Qt creator: The program has unexpectedly finished, and the official document https://doc.qt.io/qtcreator/creator-debugger-engines.html#supported-native-debugger-versions and https://doc.qt.io/qtcreator/creator-debugger-engines.html#debugging-tools-for-windows
For the crash,
My first guess is your environment variable is not set properly. Please check you assign the env. variables properly.
Writing imshow() in Qt won't work. As suggested by tr3w, you should convert to a qimage.
Mat img;
QImage img1 = QImage((uchar *) img.data,img.cols,img.rows,img.step,QImage::Format_Indexed8);
You can replace with your supported image format instead of indexed8.
I solved the problem as follows: I have added the paths to opencv's bin and lib files to PATH.
I've been struggling all afternoon to track down an issue with the Qt VS Tools in Visual Studio 2013. I'm trying to update an existing .vcxproj file that used a home-grown mechanism for generating MOC, UIC, etc. files to use the Qt VS Tools mechanism instead.
The problem I'm having is in the MOC command that's getting generated for .h files that include the Q_OBJECT macro. A sample line (reduced for brevity) is here:
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" "-I$(QTDIR)\include\QtGui" "-I$(NOINHERIT)"</Command>
The problem is that NOINHERIT doesn't exist, so the "-I$(NOINHERIT)" gets evaluated to "-I" without a value, and the MOC compiler complains and doesn't generate the MOC file. I've tried cleaning up inherited paths, checking and unchecking the "Inherit from parent or project defaults", and the only change I sometimes see is that it has "-I" without the NOINHERIT macro.
Completely starting over with a new .vcxproj file is beginning to feel like my only hope, but that's a much larger task than I'd like to take since there's a significant number of them with interdependencies that I'd rather not create again.
I'm using the latest Qt VS Tools, which is version 2.3.2. Any ideas on how to resolve this?
Naturally, five minutes after I post, I found the issue. An included property file had this:
<AdditionalIncludeDirectories></AdditionalIncludeDirectories>
Rather than this, which solved the problem:
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
Interestingly, and for what it's worth, this did not work:
<AdditionalIncludeDirectories />
Add the %(AdditionalIncludeDirectories) at project->C/C++ -> General -> Additional Include Directories.
%(AdditionalIncludeDirectories) is added by default, but if for some reason, this is overwrite by mistake, then we will get an error as such.
Moc'ing XXXXXXX.h...
Missing value after '-I'.
I'm trying to have my compiled language files copied into my output directory during the build process. I've got the copying down, but not the creating of the directory. After a lot of googling I came up with this:
LANGDIR = $$OUT_PWD
win32:CONFIG(debug, release|debug):LANGDIR = $$LANGDIR/debug/lang
win32:CONFIG(release, release|debug):LANGDIR = $$LANGDIR/release/lang
makeLang.commands += $${QMAKE_MKDIR} $$shell_path($${LANGDIR})
first.depends = $(first) makeLang
export(first.depends)
export(makeLang.commands)
QMAKE_EXTRA_TARGETS += first makeLang
This does the job for the most part, however, when the directory lang already exists, the build process fails. I know QMAKE_CHK_DIR_EXISTS exists, but I have no clue how to use that as a conditional. I figured perhaps it's something like this !$${QMAKE_CHK_DIR_EXISTS} $$shell_path($${LANGDIR}) : $${QMAKE_MKDIR} $$shell_path($${LANGDIR}) but that just crashes jom.exe; didn't really expect that to work anyways.
I'm also open to suggestions for better ways to do what I'm trying to do. Ideally the whole thing should be platform independent so I can have artifacts generated in my CI pipeline that contain the language files.
You should use QMAKE_MKDIR_CMD which creates the directory only if it doesn't exist.
I am using Eclipse IDE and I use compass to compile my .scss file. For this I have created a builder which I manually trigger whenever required. But each time I run this builder it adds lots of comments in generated .css file. I see we can use line_comments=false and that should fix my problem.
How to run compass compile without file or line reference?
But the point is where should I specify this. I don't have any compass.rb file. Can I somehow specify this in command line. As of now I am using this:
compile --css-dir=./css
Use --no-line-comments in command line argument to disable generating line comments.
Example:
compile --css-dir=./css --no-line-comments
While I used to compile a single source file with Cmd+K in prior versions of Xcode, how does one do the same in Xcode 4? (Note that this is different than preprocessing or showing the disassembly of the file.) If compiling from a command line is proposed then it must be such that the project's settings, include paths, preprocessor definitions, etc., are all included.
An example use case is where I make a header file change but only want to test the change's effect with respect to a single source file, not all of the files that depend upon that header.
The command has been moved to the Perform Action submenu. Look under
Product > Perform Action > Compile filename.cpp
To assign Cmd+K to it, go to
File > Preferences > Key Bindings > Product Menu group
and you'll find Compile File where you can assign a key. Cmd+K is assigned to Clear Console now by default, so be sure to remove that binding to avoid conflicts.
One way that I have found to do this is to using the following menu commands:
Product -> Generate Output -> Generate Preprocessed File
Product -> Generate Output -> Generate Assembly File
This may not be exactly what you want, but it will compile the single file.
When you build a project, xcode runs compilation command. You can check the log, search for your file and copy paste that command on Terminal. It'll compile only the file for which you copy/pasted on the terminal.
If your file is C (or C++) file, then simply open your terminal, go to the folder in which the file resides and type
gcc -o outputFile inputFile.c
I am not familar with Objective-c that much, but GCC might work since it's only a superset of C, just like C++.
Hope that was helpful :)
The keyboard shortcut Cmd+K on Xcode 3 and before has been remapped to Cmd+B on Xcode 4
Along the same lines, Cmd+Return was remapped to Cmd+R (in case you ever used that)
The common requirement for single file compilation is checking it for syntax errors. (atleast for me). Since xcode4 highlights syntax errors as you type. It seems apple removed that feature.