How can I connect functions on an hpp and cpp file into qt design studio? - c++

I am currently working on a project where my task is to work on the development of the UI, which I have never done before. I am encountering a lot of issues, especially with merging files from my other teammates who are working in hpp and cpp files and I must take the functions in those files to create a functional UI.
For example, what I am currently working on is creating the desktop application for the login of users, and some teammates have created functions for password encryption and authentication mechanisms that I need to merge. I notice that the files on QT creator are just .ui while on QT Design studio they are ui.qml (maybe it is the root of the problem but I don't know how to fix it)
I have already tried to add the hpp and cpp files on QT Design studio (version 6.4 of everything) but I don't see any places where I could add them and merge them. Then I tried opening and running the QT Design Studio login file on QT creator and it does not run, it just gives errors that I do not understand, such as: ":-1: error: ninja: build stopped: subcommand failed."
Is it possible to do so on QT Design Studio? If so how? If not, how do I transfer my work done on QT design studio onto QT creator? Thank you in advance for your help.

QT Design studio is just for UI designing...
The general workflow with QT C++ and QML is
to create the logic in C++ and call that logic from QML.
That is usually done via:
backends
registering C++ types to the qml engine.
Note that anything that you want to expose to QML
must exist in a QML_ELEMENT or Q_GADGET class.
callables must be either slot or Q_INVOKABLE
and variables must be property
This guide is a good introduction.

Related

How to add .ui file in Visual Studio (2010) project and compile it

I'm new in using Qt and I have a problem. I have created a simple window (.ui File) with Qt Designer and saved it.
Now I want compile it with Visual Studio 2010 . How can I add an external .ui file into my Visual Studio Project and compile it?
Should I create a new class in the project? If yes, how?
The best option (and probably the only one unless you are using CMake or similar) is to use the official Visual Studio Qt add-in (download from here): it will handle all the pre-processing steps required by some of Qt functionalities (C++ classes moc'ing, UI compilation...). It will also associate Qt files (.ui, .qrc, .ts) to respective editors.
Basically, you create a new Qt project, then create the .ui (you can use the one that comes with the template), create a class that inherits from the respective widget (QWidget, QDialog, QMainWindow) (again, there is one with the default project). From that class you setup the UI (you link the .ui and the C++ class, let's say), create slots and connect them with the UI elements, etc.
For a step-by-step tutorial please take a look at the official manual, specially the getting started section.

dynamically creating GUI in QT without using forms in visual Studio

I have installed QT5 in visual studio.
I want to create my GUI dynamically at run-time. Hence I cannot use any designers or forms. How do I do that? Which template should I create in visual Studio? Also which QT libraries do I have to include to achieve the same?
Designers and forms are only helpers that end up with generating C++ code that you want to write yourself. So you can create a form (in designer), build your project and see generated code, from which you can learn how to create and setup UI objects. You can then leave those forms aside and write your code using generated one as code snippets.
Anyway, the short answer to you question "how to create my GUI dynamically at run-time" is: create objects of UI classes (such as QMainWindow) and manipulate then using Qt API
Which template should I create in visual Studio? - C++, Win32 Project
which QT libraries do I have to include? - Again, use Qt Creator as a "teacher". Once you have a project built in Qt Ctreator, look at its "Compile output" window. From there you will learn what compiler and linker settings are needed
Practice building the forms in Qt Designer. Then go to Form -> View Code and look at the layout code. This is an example of the C++ code that you can use yourself to build widgets at run time.
When you write your own widget without designer, you can simply subclass QWidget and add buttons, dropdowns, etc. Or you can try overriding paint events to do custom painting.

Compiling and Running MFC Applications with Visual Studio 2008?

I was wondering if anyone can provide a detailed explanation on how I can compile and execute a C++ MFC application in Visual Studio 2008 given that I already have a .h and .cpp file only.
I couldn't find a decent and up to date explanation anywhere and when I try to create a plain MFC project in VS08 I get a bunch of xxx.h xxxDoc.h xxxView.h files, I try and replace those files with my own .cpp and .h files but i get a ton of errors when I run it.
So just to summarize, how do I compile and run my MFC project's .h and .cpp files in Visual Studio 2008 and create an .exe?
Thanks in advance.
See here: Creating an MFC Application
This tutorial may help you as well: Introduction to MFC Applications
It depends on what you are trying to do, but deleting the files the wizard creates is not a good idea. They are there because you told it to put them there (by selecting MFC-SDI/MDI), so they are necessary for the basic initialization and such.
If you don't need the Doc/View architecture, you can create a Dialog Based application. Or, you can even use an MDI or SDI app, and not use the Doc and the View, but if you want to delete them you'll have to make sure there are no references to them. What you cannot delete is the "MyProject.cpp" (where the CWinApp derived class lays), which does the initialization of the application.
Another option is to create a Console application with MFC support. To do so, you have to select "Win32 console application" in the wizard and then check "Add headers for MFC".

simple GUI addon to existing win console app

I've always been developing simple(console) apps. And even then most problems I had was with starting/porting/CMaking/ libraries to work.
I need to find a gui which is added/used by adding #include "somelibrary.h" to EXISTING c++ project. I've downloaded QT, but it seems I have to create a new QTproject,... and thought alone of including all CUDA,OpenCV,others is making me sick.
I've been experimenting with windows forms (.net?) but there is this managed/unmanaged border with its creepy bugs.
So I'd like to add GUI to existing project (where forms can be designed in completely separate designer).
Do you know any?
Or maybe You'd suggest me different approach?
I suggest you to use CMake and Qt. CMake is better than qmake to manage projects and use additional libraries. Currently Qt is the best multi-platform GUI API.
QT and winforms can be added on to an existing project but it's harder that taking a gui application and adding your project to it. Event driven code is organized differently than procedural code.
You don't need CUDA or OpenCV for a GUI.

What's the preferred way to include QML sources in your application build?

I am building an application with mixed UI technologies (mostly C++ with some QML components included).
Suppose I have a QML item which I want to show inside a QDeclarativeView using syntax like this:
view = new QDeclarativeView(QUrl::fromLocalFile("foobar.qml"));
I have added foobar.qml to my project in Qt Creator which automatically adds this line to the .pro file:
OTHER_FILES += \
foobar.qml
Now, you would expect including the file into the project to imply that it should be copied to the build folder, but it doesn't, and I get an error about missing foobar.qml in the build folder when I run the application. I'd hate to add custom build steps just to copy QML sources around, so is there some "de facto" way of doing this?
One obvious solution would be to include the QML source through Qt's resource system. This is hinted at on the doc page about deploying QML based applications.
EDIT: Here is the complete solution. I should learn to RTFM.
Do you use shadow builds? If so the application is build in a directory parallel to the source code. For testing you can change the working directory in Qt Creator (Projects in the left bar, then Execution of your build target).
Using resources seems fool-proof, but it requires a rebuild every time any of the resources are changed.