I have a QT widget that is functioning as a GUI for an external Process I am running. I am manually setting the path for this executable in the code. I would like to allow for the user to specify the path to the executable, from the GUI. My idea was to have some line edit box where the user enters the path, and once the path was entered it saved the path into a variable called program_path. This way when I call the process using this variable, it allows the user to choose which executable to run. I have searched the Internet, as well as stack overflow, and I was not able to find something relevant enough to what I was doing to attempt a solution. I was hoping someone could point me in the right direction as to how to implement this. Any suggested QT class or widgets to use? Any help is appreciated, in advance.
Your idea is not practical a GUI for an external Process ... I would like to allow for the user to specify the path to the executable.
If you are using an application in this way, then you should expect troubles. because giving the user that much control on your program is not good ..
QProcess can be used to run external applications but you are expected to have control inside your code .. different executables run in different ways (some are command line, some are GUI ...etc) and take different inputs (some executables run without input or switches from user , some require command line parameters ...etc) and they are different with their outputs (some apps require permissions, they give results in different ways).
Second, users are usually interested in final results not remember many executables names and details of using it.
Practically, it might be more suitable therefore to offer uses a list of choices of requests each corresponds to an executable, while you hide the details of calling each process inside your code.
To do that you need for example a QComboBox that shows users what options they have, and based on user selection you run QProcess needed to complete the action.
After all, taking a string from QLineEdit or a QCombobox is straightforward:
QString action = QLinedit::text();
QString action = QComboBox::currentText();
You might also need to show another selection process based on initial user selection, that takes more input from user and finally construct your QProccess
with all details given from user.
To allow a user to select a file or repository, I advise to use the QFileDialog class (http://doc.qt.io/qt-5/qfiledialog.html#details). It's very convenient.
Code should look like:
QFileDialog *_DialogWindow = new QFileDialog(this); // Creates a dialog window.
bool result = _DialogWindow->exec(); // Window opens. User select something in his file system. Instructions returns only once he's done.
if( result ) {
_exePath = _DialogWindow->selectedFiles().first() ; // Get the path that was selected
}
You may have to set some flags on your QFileDialog object, to specify which kind of file should be selected (.exe in your case)
Related
I have a Qt-based GUI program that runs under MacOS/X, and I'd like to be able to change the label of that program's first menu-header, i.e. the label circled in red in this screenshot:
Is there a programmatic way to do that? An objective-C/"native" solution would be sufficient, assuming no Qt-based solution exists.
Some background info (for those who rightly suspect an X/Y issue here): My MacOS/X software distribution includes several different Qt-based programs, and in order to avoid having to distribute multiple redundant copies of the shared libraries they all use, and avoid having to write a custom installer, all of the executables are placed into the Contents/MacOS subfolder of the same .app bundle, as shown in this screenshot:
To run the software, the user clicks on the .app-folder's icon to launch the "main" application, and then there are various buttons/menus in that GUI that can launch the "other" applications as child processes as necessary; and that all works well, except that the child processes' first menu's label is always shown as the name of the "main" application (as listed in CFBundleExecutable tag in the bundle's Info.plist file) rather than the child-program's own name, and I'd like to be able to change that so it shows its own program-name instead.
The following code (Swift, should be trivial to port to ObjC) changes the menu's name:
NSApp.mainMenu?.item(at: 0)?.submenu?.title = "child-program-name"
However, with this approach the menu is no longer displayed in bold once the name is changed since it doesn't match the app's name. In fact, even when changed back to the app's name the menu title is no longer bold. This seems to be a long-standing problem; see set titles of items in my app's main menu?. Unfortunately NSMenu doesn't have an attributedTitle property like NSMenuItem.
I am developing an application to feed a database. My main window is basically a menu that opens forms for different utilities.
Not sure if it's the best practice but let me explain what I'm trying to do:
my class mainwindow has a private QString that will store the current project name. In the menu, "Load" opens the form (another class) that lists all the existing projects in a combobox. The user chooses the project he wants and clicks OK.
I would like to return the combobox.currentText() into the dedicated private variable. After some research I still cannot figure out how to make it, wether I should use SIGNAL from the form to trigger a SLOT of the mainform or if there is a simple way to just return a value after pressing OK (such as an input dialog). If i am not clear enough, maybe the following sketch could help.
I definitively have a lack of knowledge on the subject but would be grateful for some help.
Indeed if your form for loading a project would emit a signal currentProjectChanged as soon as the user accepts the form (presses the OK button), this signal could be connected to a slot of the main window. For simple things this may be fine and elegant.
On the other hand reacting on actions sometimes needs more logic. If your action triggers a slot that cares for action execution, this slot probably should implement the logic. It should open the form and check whether the user has accepted the project change (pressed OK). In this case the action execution slot could get the new project name from the form and call a main window method to pass the new project name.
I've been trying to implement a file dialog into my C++ application for a while now, and I achieved good success with the code described in this article (It is german, but the code should be understandable):
https://msdn.microsoft.com/de-de/library/windows/desktop/ff485843(v=vs.85).aspx
However, using this code in my window class, which is a CDialogImpl, I just can't find out how to make this file picker modal. If I use this code, I can just spawn multiple file picker.
Of course, I could just keep track of the state by adding a member variable representing the state, but it would still not solve the problem of being able to click around in the main window while the dialog is opened.
Is there any way which would allow me to make this window modal? I've been trying to scan through all available methods, but I couldn't find anything. I didn't find any flags which could be passed in the creation, neither any options which I could set after creation.
Any help is appreciated!
The example you link to is very simple and has no UI other than the file dialog. Your program is more complex, having a window from which the file dialog is invoked.
You need to provide an owner for the file dialog. When you do that the owner is disabled, part of what makes the dialog modal. Failing to pass an owner means that the other windows are not disabled and so still respond to user input.
The example code provides no owner, but since there are no other windows in that program, that is benign. Modality is only meaningful when there are multiple windows.
So, to solve the problem, pass the owner, the handle of your window, to the Show method of the file dialog.
Disabling owner windows is one of the key parts of a modal dialog. You will find that any API for modal dialogs expects you to specify an owner. Get into the habit of expecting to provide that ownwr window, and looking for the means to do so.
I'm working with my friend to create a simple Photo Booth device. We are using DNP RX1 Printer, and this printer has the ability to cut photos in half.
When printing photos directly from windows cutting can be set as Enabled/Disabled via "Advanced Options" window in Printer Properties.
How to Enable/Disable Cut (2inch cut)
I'm working on application for this Photo Booth device (Developed on Windows 7). I'm using C++ and Qt as my GUI framework. There is a QPrintSupport module in Qt library that can be used to print images from my application, and I know how to do it. But the problem is that there is no way to Enable/Disable this "cut photos in half" option using Qt library. It is possible to display settings window to user using QPrintDialog class, but I want the process of taking photo and printing to be automatic ( User only press start button, smiles and waits till photo comes out). My workaround for this problem was to save files to two folders, and use different program to print photos from the first folder with cut option enabled and from the other folder with cut option disabled. But the problem was that printer was sometimes detected as DS-RX1 and sometimes as "DS-RX1 (Copy)" or even "DS-RX1 Copy 1", then this solution didn't work and someone had to manually delete printer from the system and reconnect it.
My question is: Is there a way to print a photo from C++ program using default printer and change this Advanced Printer Option (2inch cut) from C++ code? OR: Is there a way to force this printer to be detected always as DS-RX1?
Maybe you can set priner by substring "DS-RX1".
You can get list of available printers http://doc.qt.io/qt-5/qprinterinfo.html#availablePrinters by substring and as a variant you can set printer by setPrinterName function http://doc.qt.io/qt-5/qprinter.html#setPrinterName
I have a simple console application written in C++ that acts as a stub for launching another application through it's jumplist. Purpose is to add jumplist abilities to applications that do not support this. Call it stub.exe. When running stub.exe it creates a custom jumplist using these steps (taken right form the MS samples):
create an ICustomDestinationList
ICustomDestinationList::BeginList()
create an IObjectCollection
for_each item_to_add
create an IShellLink, set its path/arguments/title/icon
add IShellLink to the IObjectCollection
get the IObjectArray interface from the IObjectCollection
call ICustomDestinationList::AddUserTasks( IObjectArray interface )
ICustomDestinationList::CommitList()
When pinning stub.exe to the taskbar and right-clicking it, the jumpilst appears and it contains all IShellLinks added. When clicking an item, it will launch the corresponding process.
Now I'd like a process launched through this jumplist have it's window(s) grouped under stub.exe's taskbar icon, instead of having it's own group. They key to get this working seems to be the AppUsermodelID. This is what I tried so far:
just for testing, create a couple of shortcuts and set the id through IPropertyStore->SetValue( PKEY_AppUserModel_ID, "id" ). Indeed, when launching these shortcuts, they will all group under the same taskbar icon.
since the shortcuts do what I want, I tried adding shortcuts to stub.exe's jumplist: no effect. The shortcuts don't even show up in the jumplist (maybe one cannot have a shortcut to a shortcut?), yet all methods return S_OK
setting the PKEY_AppUserModel_ID on each of the IShellLinks that get added to the jumplist: no effect
calling ICustomDestinationList->SetAppID(): no effect
instead of using SubTasks, tried with SHAddToRecentDocs: no effect. The recent doc list does not show up. But now things get messy. After setting the AppUserModelID on the shortcut that is responsible for the pinned taskbar item (the one in %APPDATA%/Roaming/Microsoft/Internet Explorer/Quick Launch/User Pinned/TaskBar), the jumplist changed: it does not show the 'Tasks' item anymore, but does show 'Recent' and the items I added using SHAddToRecentDocs. Now when clicking them I get a dialog box with a title that starts with 'd:\desktop' followed by Chinese characters. Hovering the items in the jumplist also shows Chinese characters instead of the descirption I set.
Questions:
What's with the Chinese characters in the jumplist?
How come setting the app id on the taskbar shortcut toggles between 'Tasks' and 'Recent' sections, why are they not both there?
What would be the way, if even possible, to achive what I actually want: a custom jump list of which the items launched will group under it's taskbar icon? (note that the processes I plan to laucnh their do not have their app id set currently)
not much reactions here ;]
In the meantime I managed to solve the main problem myself; it's not quite a straightforward solution but it fullfills the requirements: a program runs in the backround and installs a CBT hook. Each time an application creates a window (HookProc code = HCBT_CREATEWND), the hook checks the application's path against a map containing paths and desired application ids. If a match is found, the application id of the HWND is set. Since this occurs before the window is actually shown and is combined with the custom task list, from a user's point of view the application behaves just like one that does support a recent/pinned document list.