generating GUI for C++ code - qt

i need to generate a GUI for a ready code written with C++ the code is divided into some classes containing one that represent user interface to facilitate generating GUI without big modifications on my code
and i already designed the GUI window using QT Designer
now i want to link both logical part (my classes)and GUI part(QT Designer output class) ,how to add all classes to the GUI,how to handle signals coming from GUI and send the appropriate input to the logical part
GUI
get some words from user
get slider input as an int
add files from HDD (logical part need full paths)
out some text
NOTE:first time with QT
thanks in advance for any help

You might want to start with these simple tutorials
http://www.qttutorial.com/qt/hello-qt-your-first-application/
http://www.qttutorial.com/qt/hello-qt-your-first-qt-application-part-2/

I you need a really simple solution - call this in desired order:
QInputDialog::getText();
QInputDialog::getInt();
QFileDialog::getOpenFileName();
QMessageBox::information();
QtAssistant should give you much more details and examples.

Related

How to create a SlotOfQImage in QT Rust?

I'm trying to define a custom QT Slot/Signal for passing a QImage.
I'm using qt_widgets crate which has many predefined slot types like SlotOfQIcon. However it doesn't have one for QImage. I've looked at the source code which is generated with this tool: https://github.com/rust-qt/ritual.
Is it possible to do this in regular Rust project without running complex multistage build involving code generation?
List of implemented slots for reference:
https://docs.rs/qt_widgets/0.3.0/x86_64-pc-windows-msvc/qt_widgets/
I've tried to copy paste generated code for other widgets and modify it, but it doesn't look like a right approach. I don't want to regenerate the whole library just for this case. Are there any simpler options?

Learning Qt: Which methodology to be used for this "advanced UI"?

I am learning Qt5 using PyQt.
My goal is to create a UI with several goals (I will base my need on the screenshot below).
So here are my goals:
My need
Add directories to a list of directories to be scanned (I know how to use QFileDialog.getExistingDirectory for that). For this I'd like to have a "+" button.
When pressed the QFileDialog would open and a new row would be added.
Then I would scan the directory to look for files. It won't be my first implementation but I'd like to have a circular progress bar being displayed during the scan (at the place of the classic progress bar).
When the scan is done, the UI would display the number of files found during the scan. And the progress bar would be replaced by a tick mark icon (not shown on the screenshot...).
At the beginning of each row, I'd like to have a "-" button to delete the row.
My goal is to learn
This is important, I know I am not the first one to have the idea of such a UI.
So I not looking for a third party lib on top of Qt.
My goal is to learn Qt5 (with PyQt) with this example.
But if its unrealistic, please tell me!
My knowledge
Mode View: I implemented some basic model view widgets to display strings, and I understand how to extend the idea to tables or trees.
In this case the number of rows in the table would be handled automatically.
But is it possible to created a table that would display not only strings but also widgets?
Widget Mapper: I read that another methodology is the QDataWidgetMapper. In this case, I would have to deal with creation of news rows by myself, and then I would map data onto them.
But it seems to be a hard and long job.
So, is it a good idea?
So finally could someone tell what is the best direction for that?
I am not looking for code, but since it takes a lots of time to learn new concepts, I'd like to learn and use the correct one before starting coding.
Thank you for your help :)!
After so more searches, I found that I need to use the delegate methodology.
In Qt5 it's QStyledItemDelegate and in Qt4 it's QItemDelegate.
I could find a nice tutorial at the moment, but I started coded it.

Referencing between CodeDomObjects and Text

I am writing a CodeGenerator. The string output is later on mixed with user code.
In order to be able to make changes to my generated code after the user edits the file, I have to make sure my generated parts are not editable.
I am currently not sure how to achieve this behaviour..
If I would be able to track which line correlates to which CodeDomObject and vice versa I could tell my TextEditor to mark Lines as read only.
But at this Point I have two problems.
I don't know how to keep track.
I am not sure if my solution ( which I am not able to implement... ) is
clean. There would be a lot of overhead, because I have to find out
which object is generated and which not. I could do so by comparing a
generated CodeDomTree with the actual Tree and marking the diffs as
UserObjects.
I don't know if this solution is practical in your environment but this is handled using partial classes where required in Visual Studio.
An example would be Windows Forms where the visual designer is responsible for creating source code to reproduce the form at runtime but the developer is expected to add event handling code to the class.
By having the developer's code in a separate source file it doesn't get overwritten when changes are made in the designer.
Of course, this won't help you if you need to have a single source file for your class.

Display a .dot file inside a Qt application

I am new to Qt and C++... Now, I am writing an application in Qt, in which I have to display an already generated .dot file inside my application. I tried the render function but did not work for me.. Can anyone out there help me in this regard..
Thanks
Had the same problem using Python. I came up with this solution:
svg_string = dot_graph.create_svg(prog='dot')
svgWidget = QtSvg.QSvgWidget()
svgWidget.load(QtCore.QByteArray(svg_string))
Guess you can do something similar in C++
Plotting directly a dot file requires to be able to display the nodes in the correct positions, and link them properly. This is done by very complicated engines and is not included in the dot file, which is simply a description of the graph. Maybe there are C++/Qt libraries that take dot files as an input, but I don't know them.
According to this topic (Graphviz: How to go from .dot to a graph?), you can easily transform a dot file into a png or svg file. If you want to display the rendered graph into your application, the easiest thing to do is to generate that png picture (from the shell or from your code) and to manipulate it from your program.
Take a look to QGraph. You will need much more work to make your graphs interactive.
Anyway, if you are new to Qt, even the simple display it's a steep introduction to graphics.
I have my own implementation, but I'm sorry it's not yet ready for publishing - I will do in a SWI-Prolog context...

Supplying the data for drag and drop at drop time instead of drag time

I have a Qt desktop application that works on Linux and Windows. At some point I'm hoping to port it to MacOS X and other *nix systems too.
My problem is that, a part of the application has a functionality that allows users to drag and drop files into, and out from an archive. The UI is kinda like that of WinZip or similar GUI based archivers. But Qt's drag and drop system wants the data to be prepared when the user starts dragging files from the archive.
What I currently do is, extract the dragged files to a temporary location, and supply those file names as data. But it's undesirable because extracting deep directory trees take a good amount of time, and it causes the GUI to freeze during that time. It would be nice if I could do that operation when the user decides to drop the files, not when he/she starts to drag. Unfortunately Qt docs don't say anything about this.
I know how to achieve this using Windows API, and I'm pretty sure that most systems have a way to do that too. But I want to avoid writing platform specific code as much as possible.
Is there a Qt way to achieve that? Am I missing something?
I may be misunderstanding, but I think what you want to do is supply enough information in a QMimeData for the QDrag you create that you can find the files in the archive after the user drops it without having to extract them first. So, if your code on the drop end doesn't know which archive the files have come from, you need to supply the path to the archive in your mime data, too.
The drag starts as a message:
"I'm dragging Archive1:FileA, Archive1:FileB" but no file extraction.
It ends on the other end by interpreting the message and then extracting the files. I'd probably set up some kind of simple ICD for both sides of the message transfer. If you can only drag from one archive at a time, maybe a string list with the first element being the archive and following ones being the files:
QStringList list;
list << archivePath;
list << fileName1;
list << fileName2;
QByteArray ba;
QDataStream stream(&ba);
stream << list;
QMimeData* mime = new QMimeData;
mime->setData("yourType", ba);
I hope this helps!

Resources