jerous86 / nimqt

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

QstringList error! #20

Closed Martinix75 closed 1 year ago

Martinix75 commented 1 year ago

Sorry, but it's always me! :( I have a problem on creating "qstyringlist" I am attaching the program code and error. I don't understand why "Mapit" according to him is not declared.

import std/[strformat, os]
import nimqt
import nimqt/qdialog
import nimqt/[qgridlayout,qboxlayout, qlabel, qlineedit, qpushbutton, qcheckbox, qdialogbuttonbox, qspinbox, qcombobox]

nimqt.init
let app1 = newQApplication(commandLineParams())

let label_1 = newQLabel(Q "Dimensione Font")
let linedit_1 = newQLineEdit()
linedit_1.setReadOnly(true)
let labedit_1 = newQLineEdit()
labedit_1.setReadOnly(true)

let label_2 = newQLabel(Q "Tipo Font")
let linedit_2 = newQLineEdit()
linedit_2.setReadOnly(true)
let labedit_2 = newQLineEdit()
labedit_2.resize(30,30)
labedit_2.setReadOnly(true)

let label_3 = newQLabel(Q "Grassetto")
let linedit_3 = newQLineEdit()
linedit_3.setReadOnly(true)
let ckbox_3 = newQcheckBox()
ckbox_3.setCheckable(false)

inheritQObject(Bottonex, QPushButton):
  slotDefer fontConf():
    echo("conf")
    let label_10 = newQLabel(Q "Imposta la Dimensione")
    let spinb_10 = newQSpinBox()
    spinb_10.setRange(0, 50)
    let label_11 = newQLabel(Q "Imposta il Tipo")
    let combo_11 = newQComboBox()
    combo_11.addItems(newQStringList @["Arial", "NewTimes", "Carlito"]) # --> Error: attempting to call undeclared routine: 'mapIt'
    let label_12 = newQlabel(Q "Grassetto")
    let ckbox_20 = newQCheckBox()
    let figlia = newQdialog()
    figlia.makelayout:
      - newQWidget():
        - newQGridLayout():
          - useObject label_10 at  (0, 0)
          - useObject spinb_10 at  (0, 1)
          - useObject label_11 at  (1, 0)
          - useObject combo_11 at  (1, 1)
          - useObject label_12 at  (2, 0)
          - useObject ckbox_20 at  (2, 1)
    figlia.resize(250, 250)
    figlia.setWindowTitle(Q "Finestra Figlia Fx")
    if figlia.exec() == 1:
      echo("ww")

let bottone_1 = newBottonex()
bottone_1.setText(Q "Configura Font")

let finestra = newQDialog() 
finestra.makelayout:
  - newQWidget():
    - newQGridLayout():
      - useObject label_1   at   (0, 0)
      - useObject labedit_1 at   (0, 1)
      - useObject label_2   at   (1, 0)
      - useObject labedit_2 at   (1, 1)
      - useObject label_3   at   (2, 0)
      - useObject ckbox_3   at   (2, 1)
      - useObject bottone_1 at   (3, 0, 3, 2):
        connect(SIGNAL "clicked()" ,bottone_1, SLOT "fontConf()")

nimqt.insertAllSlotImplementations()
finestra.resize(270, 270)
finestra.setWindowTitle(Q "Finestra Madre Fx")
finestra.show()
discard app1.exec()

/home/andrea/.nimble/pkgs/nimqt-0.1/nimqt/qtcore/qstringlist.nim(22, 77) Error: attempting to call undeclared routine: 'mapIt'

As usual, keep in mind that maybe I'm wrong I am! But I seem to pass the parameters correctly! Thanks for your patience and for your great job! Martin A.

jerous86 commented 1 year ago

Hi, you can solve it by doing import sequtils. Ideally, you should not have to import it manually, but it's an inaccuracy, which I don't know yet how to solve.

Just a random question: is there a reason you prefer using e.g. - useObject label_10, rather than - newQLabel(Q "foo") as label_10?

Martinix75 commented 1 year ago

Ok then "Import sequtils" on the main file (I had seen that the import in "qstringlist.nim" and therefore I had not thought of inserting it in the main file!). tnaks!

2 - I prefer to use "UsoBJECT XXX" because in the layer I prefer to insert as few things possible (like various properties that tomorrow I could decide to add), but it is only a mental setting to keep all the statements widget (and eventual properties) .. for me The code thus reads better (I repeat my personal taste).

Thanks again and good day from Andrea

p.s. 2 I added to the main file: import std/[strformat, os, sequtils]

As said in the "Qstriglist.nim" file it is already present ..

export qlist
# Additional code for qtcore/qstringlist
import sequtils
proc newQStringList*(): QStringList = QStringList()

but now i have a new error:

but now I get the following mistake ..
/home/andrea/ownCloud/In_Sviluppo/NimQt/Gui2_6_madreFx.nim(71, 35) template/generic instantiation of `insertAllSlotImplementations` from here
/home/andrea/ownCloud/In_Sviluppo/NimQt/Gui2_6_madreFx.nim(37, 38) Error: type mismatch: got <seq[QString]>
but expected one of:
proc newQList[T](): QList[T]
  first type mismatch at position: 1
  extra argument given
proc newQList[T](size: cint): QList[T]
  first type mismatch at position: 1
  required type for size: cint
  but expression '
type
  OutType`gensym36 = typeof(
    block:
      var it: typeof(items(@["Arial", "NewTimes", "Carlito"]), typeOfIter)
      newQString(it), typeOfProc)
block:
  let :tmp_469762569 = @["Arial", "NewTimes", "Carlito"]
  template s2_469762570(): untyped =
    :tmp_469762569

  var i`gensym36 = 0
  var result`gensym36 = newSeq(len(:tmp_469762569))
  for it in items(:tmp_469762569):
    result`gensym36[i`gensym36] = newQString(it)
    i`gensym36 += 1
  result`gensym36' is of type: seq[QString]
proc newQList[T](size: cint; t: T): QList[T]
  first type mismatch at position: 1
  required type for size: cint
  but expression '
type
  OutType`gensym36 = typeof(
    block:
      var it: typeof(items(@["Arial", "NewTimes", "Carlito"]), typeOfIter)
      newQString(it), typeOfProc)
block:
  let :tmp_469762569 = @["Arial", "NewTimes", "Carlito"]
  template s2_469762570(): untyped =
    :tmp_469762569

  var i`gensym36 = 0
  var result`gensym36 = newSeq(len(:tmp_469762569))
  for it in items(:tmp_469762569):
    result`gensym36[i`gensym36] = newQString(it)
    i`gensym36 += 1
  result`gensym36' is of type: seq[QString]

expression: newQList[QString] do:
  type
    OutType`gensym36 = typeof(
      block:
        var it: typeof(items(@["Arial", "NewTimes", "Carlito"]), typeOfIter)
        newQString(it), typeOfProc)
  block:
    let :tmp_469762569 = @["Arial", "NewTimes", "Carlito"]
    template s2_469762570(): untyped =
      :tmp_469762569

    var i`gensym36 = 0
    var result`gensym36 = newSeq(len(:tmp_469762569))
    for it in items(:tmp_469762569):
      result`gensym36[i`gensym36] = newQString(it)
      i`gensym36 += 1
    result`gensym36
andrea@tec-martin:~/ownCloud/In_Sviluppo/NimQt> 

It seems that "qstrringlist" desire argument @[string], while "qlist" desire [qstring] (and they do not talk :))

type
    # Classes and enums found in the C++ code
    QStringList* {.header:headerFile,importcpp:"QStringList" ,pure.} = object of QList[QString] # --> Qstring
{.push warning[Deprecated]: on.}

export qlist
# Additional code for qtcore/qstringlist
import sequtils
proc newQStringList*(): QStringList = QStringList()
# Making it a template for recursive module dependency reasons ...
template newQStringList*(xs:seq[string]): QStringList = newQList[QString](xs.mapIt(newQString(it))) #--> seq[string]
jerous86 commented 1 year ago

Yes, my mistake. I should've tested my solution. It should now work (and the import sequtils is not necessary anymore)

Martinix75 commented 1 year ago

great! Now it works perfectly! Thank you. To the next problem :)