Qt creator has cmakelists load into project

The screen-spot of the demo project I build in Qt creator I have a Source directory with several .cpp, .h and CMakeLists.txt files. I want to import this director as a project in Qt creator. There is now .pro file in my source directory. I tried the following two methods, however I still can't load this director into Qt creator.

  1. first method in Qt creator: File-> Import Project -> Import Existing Project, then it ask me to give the "project name and location". Once I gave the location of my existing source directory, Qt just built a new project for me, however, I can't see my CMakeLists.txt file in the new project. How to load my existing source files into Qt as a project with my own CMakeLists.txt??

  2. second method in Qt creator: File->Non-Qt Project->Plain C++ Application, then click choose. By this method, it can build a new project with main.cpp and CMakeLists.txt in the directory, as shown in the figure. However, once I right click the mouse on the name of the project "untitled", it seems "Add New", "Add Existing Files", "Add Existing Directories", "New subproject", and "Add library" can't be used, therefore I can add new .cpp files into this project??? Is there someone can help me figure this out?? thanks.


I'm using Qt Creator 3.6.1 and the latest version handles CMake based projects much better than the previous versions. Perhaps you should give it a try? Here's the link to the latest beta; http://download.qt.io/snapshots/qtcreator/. Of course it's not a released product yet, but I have found it to be very stable. Your mileage may vary though.

Regarding question 2, as you said "Add New", "Add Existing Files", "Add Existing Directories", "New subproject", and "Add library" are disabled because you would have to manage the project through cmake. You can edit CmakeLists.txt and rerun cmake again through "build" -> "Run CMake" or click to "Project" and "Run CMake" button on the Reconfigure project column.

If you need to create new files in the folder, then you can right click on the sub-folder name and click on "Open Terminal Here" and add/copy the needed files or choose "Show Containing Folder" for file manager.

EDIT: to add another library to your project .pro file, here's an example;

INCLUDEPATH += /usr/local/include/boost
LIBPATH     += /usr/local/lib/boost
LIBS        += -lboost_system

notice it's -l, not -L.

based on the above, your .pro should be like this;

QT += qml quick widgets
CONFIG += c++11
SOURCES += main.cpp
RESOURCES += qml.qrc
INCLUDEPATH += /usr/local/include/
LIBPATH += /usr/local/lib/
LIBS += -lopencv_core -lopencv_imgproc -lopencv_highgui

(depends on which opencv libs you will need, like -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml or others). If you need more, then you will have to supply the name of those libs.


UPDATED: From your code, here is what I tested (successfully compiled and executed); code:

int main()
    cv::Mat image = cv::imread("diffuse.png"); 
    cv::namedWindow("My Image");
    cv::imshow("My image",image);
    return 1;


QT += qml quick widgets
CONFIG += c++11
SOURCES += main.cpp
#RESOURCES += qml.qrc
INCLUDEPATH += /usr/local/include/
LIBPATH += /usr/local/lib/
LIBS += -lopencv_core -lopencv_imgproc -lopencv_highgui

Notice that I commented out qml.qrc because I don't have it. So my suggestion is for you to comment out qml.qrc, compile and run the code. If everything is OK, that means the source of error is probably somewhere in qml.qrc with regard to the image file.


EDIT: Make sure that the image is in the folder as the executable file, not with the source code file


Need Your Help

Suds error when creating a issue for Jira

python soap jira suds

i'm getting the following error every time that i try to send an issue to Jira:

How to set file size to 100 Bytes in Windows in C++?

c++ windows file file-io

Could you please tell how to set file max size to 100 Bytes. If I try to write any more data more than 100 Bytes ntwritefile() should throw error ERROR_NOT_ENOUGH_MEMORY.