QT+ CLion + Revit Issues Summary
Because I always wanted to implement the QT+CLion+Revit development path, I started learning QT and C++ from scratch. Here I record the problems encountered in QT and subsequent issues. If the development cycle is insufficient, it is estimated that I will burn the midnight oil for one or two weeks to get it out, and updates may stop at any time.
The current idea is to create a dll with C++, write the QT interface in the dll, and then use the C++ Revit API interface to implement the entire step.
The sqlite3 database component needs to be used in the middle, currently thinking of this much. Now c++ reading sqlite3 and completing the data interface has been realized.
Due to project progress, too much time was delayed in order to implement cpp+QT before, so I burned for three days during the National Day to complete the entire program, capable of creating the entire database structure model in revit. With clear ideas, the writing speed is indeed much faster. After using cpp and then using c#, I found that c# inheritance is quite easy to use. I will continue to fix this project after testing the entire project. Below are the results of all slabs. The frame structure of 21 floors is estimated to be completed within ten minutes. I tested in blocks and didn’t test centrally. I will go to the company to test tomorrow.
@[toc]
2021/09/14
SQLite3
String Transcoding with Chinese Path
1 | inline string UTF8ToGB(const char* str) |
QT
1. CMAKE File
1 | cmake_minimum_required(VERSION 3.20) |
2. mingw compilation error Must construct a QApplication before a QWidget
I referred to many links online, some said it was a problem of static library conflict caused by generating debug and release versions at the same time, others said it was a problem caused by defining global variables. Later I found that my problem was due to
1 | int main() //Before modification |
Not initializing QApplication in the class caused it. In the final analysis, it is because I am a rookie.
3. The created ui.cpp, ui.h, ui.ui three-piece set always reports errors in cpp, but does not report errors when running. First build then running is also no problem but it is still an error prompt. I don’t know if it is an IDE problem or this thing really exists.
2021/09/15
1. ui::pathwindow prompts unable to find, but can generate normally
Following the above problem, since the interface can be displayed, I ignored the error yesterday. As a result, when assigning values today, I found that I could not assign values because the ui pointer was an invalid pointer, and the ui_pathwindow.h file could not be found. I noticed that there was a comment when the QT file was generated. I studied it yesterday but didn’t go deeper because of laziness, resulting in today’s error. . . .
// You may need to build the project (run Qt uic code generator) to get "ui_pathWindow.h" resolved
The comment tells us that before building the project, we should use uic to generate ui_pathwindow.h first. The following are the steps to use uic, refer to blog: Use of uic tool in QT
- Directly search for the QT console program in the Window search interface. Because my program uses MinGW64, select the corresponding version.

- Click to enter the project file. I cannot enter cd here, I can directly input the drive letter, and then execute the cd command.
- Because my ui file is in a separate ui folder, so first qmake create project, use command:
qmake -project,qmake ReadDatabase.proAfter qmake project, there will be a .pro file, you can go to the folder directly to check the name. - After that, cd into the ui file and execute the uic command
pathwindow.ui -o ui_pathwindow.h, the header file name can be named according to your own UI file.
connector function invalid
If you use the old way of writing connectors in QT 5, i.e., connector( , SINGNAL() , ,SLOT())
You will find the function invalid, for example, listview cannot call out clicked function. At this time we need to use the new writing method, directly call the function under the corresponding component, such as: QListview::clicked. If it is a function written by yourself, directly pathWindow::show can be called. Specific operation can refer to Bean’s blog.
2021/09/16
1. Unable to update format after modifying ui file using external tools in CLion
Solution, referring to the difficult problem above, enter the ui file location and enter the command uic pathwindow.ui -o ui_pathwindow.h to regenerate the ui-pathwindow.h file. If you have time, you can directly modify the .h file. Small components can be modified like this. If the changes are large, it is better to run it again.
Error when compiling with MinGW-64: multiple definition of xxx
Solution: Use inline functions. Reduce duplicate definitions through inline functions to solve this problem.
Generated QTlistview The bottom row of data is always unable to display completely
After regenerating the .h file again, it can be displayed normally. Not clear about the specific reason, todo:
qlistview add checkbox
If you want to add checkbox to listwidget, refer to the following link: http://www.qtcentre.org/threads/47119-checkbox-on-QListView
code:
1 | for (int i = 0; i < count; ++i) { |
Difference between listview and listwidget
listview inherits from model class, listwidget inherits from item. listview is relatively flexible, listwidget is convenient to operate. Specific explanation refer to link: Difference between QListView and QListWidget
2021/09/17
After adding Checkbox in QListview, how to click the row to change Checkbox status.
- Because ListView inherits from Model, data is stored in Model. If you want to get data of a certain row or data of Checkbox, you need to enter QAbstractiteModel, get the specific value of a certain column of the changed row as QVaiant type. Data assignment in QT is based on the corresponding Role. Like Checkbox, it is CheckStatusRole. If purely data, just export directly. If customized, add forced conversion.
1 | int r_count = ui->listView->model()->rowCount(); |
Implement clicking button to open FileDialog dialog box
The separation of Filter here uses spaces, as shown in the example below
1 | QString fileName = QFileDialog::getOpenFileName(this, tr("open the data file"), "D:/", tr("files(*.db *.ydb)")); |
QTableview simple initialization and assignment
1 | //ui style |
vector<> Passing string using const char* in custom class is null value
I defined a class, using const char* to record string value in the class, but when the value is stored in vector container, the corresponding string value becomes null. It should be that vector stores data as a pointer. const char points to failure at this time. Changing to string type can verify display normally*
Change file separator ‘ \ ‘ ‘/‘
File path separator in QT is / used in Linux. In Windows, the separator needs to be changed to \. At this time, functions are needed for conversion. Source: https://blog.csdn.net/Littlehero_121/article/details/115078556
1 | QDir::toNativeSeparators(fileName).toStdString().c_str() |
2021/09/22
After struggling with gastroenteritis during the holiday, now continue writing the program -.-.
Array out of bounds, caused by unstandardized code checking by myself SIGTRAP (Trace/breakpoint trap)
Before the festival, getting data of a module, found that it kept reporting SIGTRAP (Trace/breakpoint trap), or Process finished with exit code -1073740940 (0xC0000374). Open search engine and started copy pasting, found array error, or array reading out of bounds or destructor error. For this reason, I changed my class structure and found that it was still this error. Finally found that it was because the pointing in the factory pattern was wrong, pointing the slab class to the floor class, so reading the vector container directly reported an error. However, if encountering array out of bounds problems in the future, can refer to the following blog to solve. c++ debug reports Unknown Signal or Trace/breakpoint trap exception when container releases memory
2021/09/24
The function of the program is basically completed. Simply put, it is data reading and organization of the database. After completion, because it needs to be associated with Revit, VC++ needs to be used in the middle. For convenience, the window program is packaged into a dll for convenient later use. Some problems encountered in the middle are recorded.
How classes with dll windows generated by CLion are called by other c++
- For ease of testing, I modified the original dynamic link file to an executable file, just change CMAKElist a bit
1
2
# add_executable(ReadDatabase ${SOURCE_FILES})
add_library(ReadDatabase SHARED ${SOURCE_FILES})
Unable to generate dll file after modifying CMAKE generation file format
After modifying the cmake file, it was found that the dll file could not be generated. It was found that deleting the existing .exe executable file can successfully generate it.
Method of statically loading dll
CMAKE file, we use the static loading method. Regarding static loading or dynamic loading, refer to Windows: writing and dynamic/static calling DLL under CLion. Recreate the project and write the cmake file, load the lib to use. Note one thing here, if things are like me and need to load a dll with a QT window, you need to copy the three dlls starting with QT under the project file debug together, otherwise it will always report error unable to find file. This kind of error debug will not prompt either. Error name is: Process finished with exit code -1073741515 (0xC0000135). At this time we need to copy the file under the debug file, as shown below. Afterwards modify CMAKE file same as the window file, configure QT environment well, then you can reference corresponding content, see below

Making function interface for calling dll
To call, you need to expose part of the functions in the dll file, define in header file using extern "C" __declspec(dllexport) int hello2(int argc , char* argv[]); and implement in cpp file, then declare function in reference file to use function interface to implement function
1 |
|
2021/09/25
C++ exe file execution error missing necessary dll file
- add command to cmake file
1 | set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") |
- If adding 1 still reports error, copy corresponding dll from bin folder of MinGW and place in same directory
2021/09/28
multiple definition of problem
Yesterday I defined a singleton class to export interaction data as an export class. After creating the singleton mode, running reported duplicate definition error. The location was in my ui_pathwindow.h and unit.h. According to online methods
- Duplicate file reference in .pro file. After checking, not this problem.
- Use extern keyword, didn’t use because too troublesome.
- Check if class name duplicate naming caused generation error. Still reported error after renaming to unique name.
Finally blog and github case. The blog warned specific content to be written in cpp file, do not define content in header file, singleton initialization also completed in cpp, case is also written separately, properly run after compiling splitting original singleton mode into .h and .cpp.
1 | pathwindow.h |
function ‘IDLL* GetObj()’ definition is marked dllimport
Using macro definition dll export interface error, unable to mark dllexport, need to place macro definition above #include, let compiler compile macro command first to solve.
1 | extern_dll.h |
2021/10/15
Referral Link
- Qt5.8 generate dll and call detailed graphic tutorial
- QT window calls sub-window flash away problem
- Make interface in qt into dll for calling
QT create dll and reference
Continuing to fix previous issues today. Considering that the QT window was created in CLion before, and used QMainWindow class, so this time transplanted the project to QT Creater and used QWidgets class to create, the overall is the same as before except modification of export function is different.
QT Creater export class file writing
Or is different from macro definition when writing c++. If QT creates Library directly, you will get a *_global file. Directly copy file macro definition and delete this file.
1 |
|
Undefine problem linking sqlite3
Because it is a project transplant, so QT += sql configuration mode was not used. Add library by right clicking project select external library, select your own lib folder to configure, I wrote absolute path directly in header file here, haven’t modified trial and error yet
1 | win32: LIBS += -L$$PWD/../lib/ -lRDstrucalSource |
Link dll
Same operation steps as above link library, copy interface dll, .a, .h files to a folder and add external connection, directly quote header file in project to use.
1 |
|
Situation where interface flashes away in QT linked dll file
Actually it is application of stack, we can create window pointer, show(), program will wait for interface to complete running before continuing to run subsequent programs.
1 | void GetObj::MakeShow() |
Nothing happened this afternoon. Tried my own ideas currently everything normal. Complete mutual calling between mingwc++ projects when off work. Continue vc++ calling tomorrow. Put a result picture.





