Closed grd closed 1 year ago
Do you get the same behaviour with the script below? It runs following programs
load_ui_example.ui
is replaced with foo.ui
load_ui_example.ui
to foo.ui
.I think 1. and 2. describe the steps that you wrote, right? For me I get first the regular example, then a new form, and then the first one shows again. What is your output? Am I understanding you still wrongly?
# pwd
$HOME/nimqt-github/ # we're at the root of the repo
# cat issue5.sh
#!/usr/bin/env bash
mkdir -p tmp/issue-5/
cp examples/load_ui_example.ui tmp/issue-5/
cat <<- EOF > tmp/issue-5/foo.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2"> <widget class="QPushButton" name="btnEnable"> </widget> </item>
<item row="1" column="0" colspan="2"> <widget class="QPushButton" name="btnUndo"> </widget> </item>
<item row="2" column="0" colspan="2"> <widget class="QPushButton" name="btnRedo"> </widget> </item>
</layout>
</widget>
</ui>
EOF
cp examples/load_ui.nim tmp/issue-5/load_ui.nim
nim cpp --path:qt/6.4.1_minimal/ -r tmp/issue-5/load_ui.nim
sed 's/load_ui_example.ui/foo.ui/g' examples/load_ui.nim > tmp/issue-5/load_ui.nim
nim cpp -f --path:qt/6.4.1_minimal/ -r tmp/issue-5/load_ui.nim
cp load_ui_example.nim foo.ui
nim cpp -f --path:qt/6.4.1_minimal/ -r tmp/issue-5/load_ui.nim
# bash issue-5.sh
I think that I know what is wrong. This is the answer that I got from compiling after copying my other ui file to load_ui_example.ui
/home/user/nimqt/examples/load_ui.nim(4, 13) Error: cannot open file: nimqt/qdialog
And that is because in my other ui file (I looked inside it) is stated: <widget class="QDialog" name="Dialog">
and yours is with <widget class="QWidget" name="Form">
So... it is clever enough to fool me ;-)
And I think that I am wrong into thinking that it looked into historical data. I think that the solution lies into creating a loadUi() proc for QDialog in the form of
var rootDia: ptr QDialog
rootDia.loadUi(curFileDir/"load_ui_example.ui", createConnections=true)
Edit: Btw, why don't you rename init() into initQt() then you don't need to add nimqt.init() but only initQt()
I thought I had added the qdialog
class :) I just pushed a commit which should have it.
Still don't understand exactly about the historical data, but I assume that is fixed now?
You can skip btw the createConnections=true
-- its default value is true.
You can also just call init
, but in this case I prefer to just add the module prefix.
Still don't understand exactly about the historical data, but I assume that is fixed now?
I understand now that is because it just didn't compile and when I ran the program it just shows the old file. Sorry, my mistake.
It is still not working correctly. I pulled out your github and I changed your program with this:
import os
import nimqt
import nimqt/[load_ui, qdialog]
nimqt.init
let app = newQApplication(commandLineParams())
# We use `curFileDir`, defined in nimqt/load_ui to get the directory of *this* file.
# loadUi works best with absolute paths.
var rootWg: ptr Qdialog
rootWg.loadUi(curFileDir/"load_ui_example.ui", createConnections=true)
btnUndo.setEnabled(false)
btnRedo.setEnabled(false)
rootWg.show()
discard app.exec()
And the error is still the same.
Changing
var rootWg: ptr Qdialog
to
var rootWg: ptr QWidget
makes it work for me.
I'll figure out later a way to get the correct type and make it work with the correct type.
Then I am gonna close this. Thanks!
Should be fixed!
I created a couple of empty dialogs/windows/widgets to work with. They don't compile ATM.
Can you maybe also add the nim code used to test it? Some ui files just worked for me. What compilation errors do you get?
I added the QDialogButtonBox module, which should fix some ui files, I think.
It is only a reference. I got some errors too. QDialogButtonBox is important indeed 😉
I can make the test files, should I put every widget inside? Does that work?
But it's gonna be tomorrow because I am tired ;)
Edit: Stupid. I have the designer and can make a list of the things that are missing.
I prefer examples where I can just run nim cpp --path:qt/6.4.1_minimal $(your_file).nim
So preferably, there would be one .nim file for each .ui file (but the .ui file can indeed contain all necessary widgets) :)
Sorry to be so late but I did have some personal issues that I needed to solve.
I tried to open a couple of complex files and they all didn't load. The files are from FreeCAD and this is the link to the ".ui" files from the Arch WB: https://github.com/FreeCAD/FreeCAD/tree/master/src/Mod/Arch/Resources/ui
From loading nim cpp --run preferences-arch.nim
I got this error: /home/user/.nimble/pkgs/nimqt-0.1/nimqt/load_ui.nim(57, 25) Error: cannot open file: nimqt/qdoublespinbox
[ui.tar.gz
ui.tar.gz ](https://github.com/jerous86/nimqt/files/10456177/ui.tar.gz)
But unfortunately I got a lot more errors.
Will take a look at them one of the days!
These are only examples, but I think that they are pretty good.
If you do a pull, I think you should be able to load the examples. I added most of the QWidget classes, and the ui-loader now also replaces customwidgets with their base class. This will cause a loss of functionality, but it will at least show the form :)
When you do update, you might have to change some paths, as I updated Qt to 6.4.2 and changed the distribution from "minimal" to "gui_widgets".
Thanks! Now it works!
You can try it with simply replacing the text string in
load_ui.nim
.For instance I wrote the following line
rootWg.loadUi(curFileDir/"edit_item.ui", createConnections=true)
and it loads the same "load_ui_example.ui" as with the original version. This why I said that it appears to look into the history.