jerous86 / nimqt

Qt bindings for nim
GNU General Public License v2.0
93 stars 6 forks source link

Problems with icons in Nimqt 0.2.0 #35

Closed Martinix75 closed 7 months ago

Martinix75 commented 8 months ago

As I anticipated, for the same code, you can no longer load the icon on the window, the code that placed, previously it worked, now from an error:

import os
import nimqt
import nimqt/[qlabel, qpushbutton, qspinbox,  qicon]
import nimqt/[qwidget, qboxlayout, qgridlayout, qdialogbuttonbox]

nimqt.init

let pwmApp = newQApplication(commandLineParams())
let lab1 = newQLabel(Q"Set PWM")
let sbx1 = newQSpinBox()
sbx1.setRange(0,100)
sbx1.setsuffix(Q" %")
let lab2 = newQLabel(Q"Set Time")
let sbx2 = newQSpinBox()
sbx2.setSuffix(Q" Min")
sbx2.setMinimum(0)

let sbx3 = newQSpinBox()
sbx3.setSuffix(Q" Sec")
sbx3.setRange(0, 59)

inheritQObject(Pippo, QObject):
  slot_decl io()

let icona = newQIcon(Q"panoratux.png") # <---- !!!!! NOT WORK in 0.2.0!!!
echo "ciao"
let gui: ptr Pippo = newPippo()

let finestra: ptr QWidget = newQWidget()
finestra.makeLayout: #cosi sembra un layout verticale...
  - newQWidget():
    - newQHBoxLayout():
      -  use_object lab1
      - use_object sbx1
  - newQWidget():
    - newQHBoxLayout():
      - use_object lab2
      - use_object sbx2
      - use_object sbx3
  - newQDialogButtonBox(newQFlags(QDialogButtonBox_StandardButton.Ok)|newQFlags(QDialogButtonBox_StandardButton.Close), finestra):
      connect(SIGNAL "rejected()", finestra, SLOT "close()")
      connect(SIGNAL "accepted()", gui, SLOT "io()")

proc io(this: ptr Pippo) =
  echo "Valore Accettato...."
  echo (sbx1.text)
  echo (sbx2.text)
  echo (sbx3.text)

finestra.setWindowTitle(Q"TestPWM")
finestra.setGeometry(160, 140, 300, 100)
finestra.setWindowIcon(icona)
finestra.show()
discard pwmApp.exec()

errore:

/home/andrea/ownCloud/In_Sviluppo/NimQt/Cap1-Dialogs/controlLed.nim(27, 32) Error: type mismatch: got 'QIcon' for 'newQIcon(Q"eco.png")' but expected 'ptr QIcon'
andrea@localhost:~/ownCloud/In_Sviluppo/NimQt/Cap1-Dialogs> nim cpp -r controlLed.nim 
Hint: used config file '/home/andrea/bin/nim/config/nim.cfg' [Conf]
Hint: used config file '/home/andrea/bin/nim/config/config.nims' [Conf]
.............................................................................................................................................................................................................................................................................................
CC: controlLed.nim
/home/andrea/.cache/nim/controlLed_d/@mcontrolLed.nim.cpp:237:45: error: ‘T9_’ was not declared in this scope
  237 | N_LIB_PRIVATE QIcon icona__control76ed_u263(T9_);
      |                                             ^~~
Error: execution of an external compiler program 'g++ -c -std=gnu++17 -funsigned-char  -w -fmax-errors=3 -fpermissive -pthread -std=c++17 -I/home/andrea/.nimble/pkgs2/nimqt-0.2.0-574212c0eb363ee4148c7ec83eab6183e9440ee4 -I/usr/include/qt6 -fPIC -I/usr/include/qt6/QtCore -I/usr/include/qt6/QtGui -I/usr/include/qt6/QtWidgets   -I/home/andrea/bin/nim/lib -I/home/andrea/ownCloud/In_Sviluppo/NimQt/Cap1-Dialogs -o /home/andrea/.cache/nim/controlLed_d/@mcontrolLed.nim.cpp.o /home/andrea/.cache/nim/controlLed_d/@mcontrolLed.nim.cpp' failed with exit code: 1

If you want to try it, I think it is sufficient to put an icon of your choice next to this file! (with Nimqt 0.1.x) it worked! Hello and good evening! P.S. I'm now trying the "mianwindow", prepared for the worst :)

Martinix75 commented 7 months ago

I understood (and solved the problem .. maybe), written so by problems, NOT work:

nimqt.init
let app1 = newQApplication(commandLineParams())
let icona = newQIcon(Q "Icons/panoratux.png")
etc.....
finestra.setCentralWidget(centrale)
finestra.setWindowTitle(Q"MainWindow")
finestra.setGeometry(600, 500, 250, 150)
finestra.setWindowIcon(newQIcon(icona)
finestra.show()
discard app1.exec()

Written like this it works (even in the Mian Window menus):

#let icona = newQIcon(Q "Icons/eco.png") <-- now commented !!
.....
finestra.setCentralWidget(centrale)
finestra.setWindowTitle(Q"MainWindow")
finestra.setGeometry(600, 500, 250, 150)
finestra.setWindowIcon(newQIcon(Q "Icons/panoratux.png"))
finestra.show()
discard app1.exec()

So I would say that the post can be closed! bye by A. Martin