Reputation:
So I figured out how to get Qt Framework working with CLion, but I don't have Qt Designer in CLion. How can I make a GUI in CLion using Qt Framework? Every tutorial i've seen uses Qt Creator so I cannot get an answer.
Upvotes: 1
Views: 1437
Reputation: 963
I worked with QtCreator and then with Qt5 libraries on Clion. For a better understanding see my project at https://github.com/FraScandiffio/Timer_Laboratorio Search for MyTimerApp.ui .h .cpp files.
1)You need a .ui file: it was created for me by QtCreator: when i worked on Clion i just copied the file into my project folder and add in the SOURCES_FILES. You can download it from my project: it's the MyTimerApp.ui file but you have to change just 3 words to adapt it to your needs.
Re-name the file with the name that you prefer. Now open the file with a text editor and replace all the "MyTimerApp" with the name that you have just chosen.
2)Add this in your Cmake.txt (the explanation of why you have to do it is here)
cmake_minimum_required(VERSION 3.3)
project({your_project_name})
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(SOURCE_FILES main.cpp MyApp.ui #...)
#... the rest of your cmake.txt ...
Download also MyTimerApp.cpp and MyTimerApp.h files. (i suggest you to create a new .h file and paste into them the code instead of refactor my file) Open it and replace "MyTimerApp" whit the same name you have chosen before. obviously add them into the SOURCE_FILES list.
In the main.cpp type
#include "nameyouhavechoosen.h"
#include "QApplication"
#include "QWidget"
int main(int argc, char *argv[]){
QApplication app(argc, argv);
QWidget* MyWidget= new {nameyouhavechoosen};
MyWidget->setGeometry(500,200,617,416);
app.setActiveWindow(MyWidget);
MyWidget->show();
return app.exec();
}
If you run it you should see a very simple window. In my github repository you can find how to create buttons/timer and more. Anyway Qt documentation is great for learning.
Upvotes: 1