How can I get a QFileDialog to prompt for overwrite? - qt

I have a QDialog that opens a QFileDialog like so:
QFileDialog fd(this);
fd.setFileMode(QFileDialog::AnyFile);
if (fd.exec()) {
// save data to a file
}
Unfortunately, the default behavior doesn't seem to be quite so default, and the file dialog doesn't prompt me about overwriting if I select a file that already exists. Calling setConfirmOverwrite(true) or setOption(QFileDialog::DontConfirmOverwrite, false) first doesn't help either. I've tested this both on Qt 4.7.3 and 4.7.4 on both Ubuntu 11.04 and Windows XP.
I looked around and found this bug report. QFileDialog::getSaveFileName() had this issue, but it was specific to Maemo and fixed well before Qt 4.7.3 came out. If I use that method in my application it works just fine, I get prompted about overwriting the file. (I don't want to use getSaveFileName() for unrelated reasons.)
I can't find anyone else complaining about this not working for them. Am I doing something wrong, or is this a bug? I think it might be due to the dialog not knowing whether it's just a simple Open dialog where prompting wouldn't make sense, but I don't see a way to tell it it's a Save dialog (beyond setting the confirm-overwrite option, which fails), and the documentation does say it should prompt by default.

You should also be sure that the dialog is in save mode, as it will not think you are overwriting a file when in open mode. You can do this by calling fd.setAcceptMode(QFileDialog::AcceptSave); in your code example. See QFileDialog::acceptMode.

Related

Tosca: Can we scan Notepad.exe?

So, as I'm learning Tosca, I tried to scan the simple program Notepad.exe that comes with windows... and I can't seem to figure it out. Is it even possible with Tosca 9.2? Is it possible with Tosca 10?
The best I was able to do so far was to scan Notepad as an "other", and switch on the Options > Use UIAEngine... and then it was only really able to see the main editbox... menu headers could be scanned, but none of the menu options like file > Open... or Edit > Replace... which would make being able to automate Notepad.exe useful.
Is it just not possible yet?
It is possible with TOSCA 10. I just tried and scanned Notepad instance with Desktop option from Module Folder > [right click] Scan Application > Desktop. It shows all the open browsers, Notepad instance, folders and desktop.
I scanned a module of Notepad which had only two attributes (because I selected only those) - Text area of Notepad and its close button. I created a test case where I inputted 'This' in the text area and clicked the close button. The test case also works fine.
Hope this helps!
The performance is much faster if you use the below modules instead of opening it UI. You can read/write and play around in the text file.
TBox Read/Create File
File system operations
TEXTSTREAM

Brackets - unable to edit defaultPreferences.json file (trying to set linting to jshint but not jslint)

I am running Brackets on a macbook pro and when I press cmd+, and try to edit the defaultPreferences.json file, it does not allow me to make any changes to the file (nothing happens when I type). If I restart Brackets I can edit the file, but after closing and re-opening the preferences file, the changes are reverted.
I have tried editing the json file with TextEdit while Brackets is closed, but Brackets still likes to reverse the changes.
I had similar issue , and i did open issue at Bracket's GitHub repository and here is the solution from its developers:-
defaultPreferences.json is a read-only file: take the options you
want to modify and copy them to the brackets.json file on the other
pane. This will override the defaults. You will also see code hints
while typing the values in to brackets.json which will help picking
the correct options.
Now it is also available to install brackets-preferences plugin and edit from there. Once installed go to View -> Preferences in your Brackets interface to edit preferences.

Change virtual keyboard to AZERTY

I have a javafx application that is supposed to run in fullscreen mode on a Windows tablet.
My problem is, when the keyboard appears, it's in QWERTY whereas my tablet is in AZERTY.
So the question is : Is there a way to use the system virtual keyboard or to switch the javafx virtual keyboard to AZERTY?
I found you question while trying to accopllish the same thing.
I spent a day trying to make javafx display an AZERTY keyboard and i found a solution!
Well let me be clear : javafx gave no way at all to have an azerty keyboard so you have to hack a little.
The solution bellow is not a perfect one and you'll have to repeat it each time you update javafx, but it will allow you to extrem customize the keyboard far beyong querty and azerty.
SOLUTION 1 (dirty but works )
You will need to edit a file in javafx file shipped with the JDK
STEPS :
GO to the JDK (in Mac : /Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home)
Go inside jre/lib/ext and copy javafx jar called jfxrt.jar to a folder on your desktop.
Install EMACS if you don't have it and open the copied jar file with this software
Browse files list searching for com/sun/javafx/scene/control/skin/TextBoard.txt
the list is sorted from A-Z so use it (there is more than 6000 files).
Open it and HERE you are. Change characters to whatever order makes you happy. I joined the azerty order.
Save and copy back the jfxrt.jar to where it was. Done.
Note: don't try to extract the jar and rezip it, it won't work as jdk keeps an index list of files.
Result:azerty javafx virtual keyboard in action
SOLUTION 2 (Clean but i didn't finish it)
Whene i digged into javafx classes i found out that the class responsible for loading the TextBoard.txt file that lays out the keyboard is FXKVSkin
This class is meant to receive other type of keyboards than the lonly qwerty default one.
All you have to do is add this in your code :
textFieldThatYouUse.getProperties().put(FXVK.VK_TYPE_PROP_KEY,
"mykeyboard");
Where mykeyboard is a file you created like TextBoard.txt called MykeyboardBoard.txt (capitals letters are important).
FXKVSkin will look now for a file called MykeyboardBoard.txt, and here's where my adventure ended.
You will need to make FXKVSkin find your file, i tried by adding a file to the classpath at runtime solutions Here but it didn't work.
If anyone can solve this problem, please add it as an answer, it would be a less dirty solution.
Hope the solutions will help some non english speakers! :p
The definition of the layout is contained in jfxrt.jar (part of the Java install). It is described by TextBoard.txt. It is possible to browse in the jfxrt.jar with 7zip or similar programs. TextBoard.txt is in com/sun/javafx/scene/control/skin/
This file is loaded com/sun/javafx/scene/control/skin/FXVKSkin.java is responsible for loading the TextBoard.txt file. Browse the javafx source (included via the jdk and contained in javafx-src.zip) to see how it is processed. Maybe this will give you enough information to load your own TextBoard.txt file.

QWidget::showMinimized() doesn't work

On Ubuntu 13.04, if using QWidget::showMinimized() to minimize a window, I found that after restoring it by clicking the app icon the system taskbar, recalling the QWidget::showMinimized() cannot work.
connect(minimumBtn,SIGNAL(clicked()),this,SLOT(minimumWin()));
minimumWin(){
showMinimized();
}
showMinimized() in minimumWin() doesn't work anymore if it has been called before (even the window is showed).
I can reproduce this with Linux Mint and Qt 5.1. It is most probably a bug in Qt. I found that if you call showNormal() right after showMinimized(), the window minimizes and after it is restored from the taskbar, it is possible to minimize the window again. For example:
void MainWindow::on_pushButton_clicked()
{
showMinimized();
showNormal();
}
I've met this problem, but I didn't solve it completely
In ubuntu system, you can use this function in your QWidget class constructor:
this->setWindowFlags(Qt::Window|Qt::FramelessWindowHint||Qt::WindowMinimizeButtonHint);
then the showMinimized() is valid to use (there is no frame and a minimize button when code running, if you have, then you're with me).
But it's only valid in ubuntu system, and this method is invalid in my company's customized (like ubuntu) operate system. I don't know why.

QVision Widget Error upon compile

Only one error to go until I get to use this for my research!
Warning: Z-order assignment: " is not a valid widget.
FILE: qvvideoreaderblockwidget.ui
There's no line number that came with it. I tried finding but, failed to see an open-ended part.
What should I do to correctly compile this library?
Edit the ui file outside of Qt Creator. Delete the rows with 'zorder' tags. Then open in Qt Creator and compile again. It worked for me then perfectly, the warning did not appear any more.
OK, I had this, and it irked me too. I don't know what happened to cause this, but it is not serious. I suppose that breaking and remaking all the layouts might fix it. Other frameworks tend toward a lot of warnings, but tho I'm new to Qt, not a one yet. I went in another editor, and removed a line that said (as best I can remember):
<z-order>verticalSpacer</z-order>
which was among a lot of other lines which also were z-order tags. I deleted the line with this tag, and rebuilt all. Problem gone. Interestingly enough, all of the z-order tags had vanished from my file when I looked at it next. It must be a bug, but evidently one of little consequence; except those who hate to see the serene beauty of Qt spoiled.
Does the ui-file qvvideoreaderblockwidget.ui contain "Promoted widgets"? If so, use the "Promoted widgets" dialog of the (Qt4-) designer for ensuring that the header of the promoted widget-class is declared as "global include".
In case the custom widget class is named "MyWidget" and the header is named "mywidget.h" and the member widget shall be named "myWidget", the uic will generate the code of the ui-class as follows:
#include <mywidget.h>
class qvvideoreaderblockwidget
{
public:
MyWidget* myWidget;
// ...
};
It happened to me when I deleted a fairly large chunk of stuff in the designer. Investigation showed that the designer had failed to remove a zorder tag relating to the widget I deleted (which, incidentally contained a bunch of other widgets).
Deleting the line as suggested cleared the problem. If you do have a load of zorder tags you probably need to be careful to just delete the one that relates to the deleted item.
I had the same problem, and deleting the .exe file from the output folder (debug or release) before run/compile the source, solved the problem.
This problem arises due to a (presently) unfixed bug in Qt Creator's undo / delete mechanism.
The solution until the bug is fixed is to:
Close the .ui file in Qt Designer
Open the .ui file in an external editor
Delete the <zorder> line(s) that apply to the element with the problem. For example:
<zorder>groupBox_2</zorder>
Save the file
Re-open the file in Qt Designer
Re-compile in Qt

Resources