jerous86 / nimqt

Qt bindings for nim
GNU General Public License v2.0
103 stars 8 forks source link

'slot/slot_defer' compilation error #51

Open matkuki opened 4 days ago

matkuki commented 4 days ago

Hi,

I'm on Windows x64, Nim devel, nimqt head. This is my object override:

inheritQObject(AdvancedTabBarButton, QGroupBox):
    var name: QString = ""
    var title: QString = ""
    var image_path: QString = ""
    var labels: seq[ptr QLabel] = newSeq()
    var value: bool = false
    var pressed: bool = false
    var dragging: bool = false
    var position_cache: QPoint = newQPoint(-9999.cint, -9999.cint)

    # Signals
    signal signal_click(name: QString, button: int)
    signal signal_close(name: QString)
    signal signal_drag_start()

    # Slots
    slot_defer onclick(name: string, button: Qt_MouseButton):
        if button == Qt_MouseButton.LeftButton:
            if name != "close":
                echo "click"
            elif name == "close":
                echo "close"

Compilation in Nim succeeds, but the MSVC++ compilation fails with:

.Hint: used config file 'C:\Users\...\.choosenim\toolchains\nim-#devel\config\nim.cfg' [Conf]
Hint: used config file 'C:\Users\...\.choosenim\toolchains\nim-#devel\config\config.nims' [Conf]
Hint: used config file 'E:\TEST\nim.cfg' [Conf]
[NimScript] exec: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Auxiliary/Build/vcvars64.bat
**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.11.37
** Copyright (c) 2021 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
[NimScript] exec: nim cpp --cc:vcc --outdir:build --mm:orc --nimcache:nimcache --passC:" -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:throwingNew -Zc:externConstexpr -O2 -MD -utf-8 -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DNDEBUG -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -IC:\Nim\lib -IE:\Qt6\6.3.1\msvc2019_64\include -IE:\Qt6\6.3.1\msvc2019_64\include\QtWidgets -IE:\Qt6\6.3.1\msvc2019_64\include\QtGui -IE:\Qt6\6.3.1\msvc2019_64\include\QtCore -I/include -IE:\Qt6\6.3.1\msvc2019_64\mkspecs\win32-msvc -I.\dependencies\nimqt\qt\6.4.3_most /Zc:strictStrings-" --passL:" /NOLOGO /DYNAMICBASE /NXCOMPAT /OPT:REF /OPT:ICF /INCREMENTAL:NO /SUBSYSTEM:CONSOLE " --clib:E:\Qt6\6.3.1\msvc2019_64\lib\Qt6Widgets --clib:E:\Qt6\6.3.1\msvc2019_64\lib\Qt6Gui --clib:E:\Qt6\6.3.1\msvc2019_64\lib\Qt6Core --clib:E:\Qt6\6.3.1\msvc2019_64\lib\Qt6EntryPoint src/exco.nim
Hint: used config file 'C:\Users\...\.choosenim\toolchains\nim-#devel\config\nim.cfg' [Conf]
Hint: used config file 'C:\Users\...\.choosenim\toolchains\nim-#devel\config\config.nims' [Conf]
Hint: used config file 'E:\TEST\nim.cfg' [Conf]
Hint: used config file 'E:\TEST\src\exco.nim.cfg' [Conf]
.....................................................................................................................................................................................................................................................................................................................
E:\TEST\dependencies\nimqt\qt\6.4.3_most\nimqt.nim(70, 25) Warning: imported and not used: 'qstring' [UnusedImport]
.........
E:\TEST\dependencies\nimqt\qt\6.4.3_most\nimqt.nim(316, 27) Hint: 'signal_click' is declared but not used [XDeclaredButNotUsed]
E:\TEST\dependencies\nimqt\qt\6.4.3_most\nimqt.nim(316, 27) Hint: 'signal_drag_start' is declared but not used [XDeclaredButNotUsed]
E:\TEST\dependencies\nimqt\qt\6.4.3_most\nimqt.nim(316, 27) Hint: 'signal_drag_start' is declared but not used [XDeclaredButNotUsed]
E:\TEST\dependencies\nimqt\qt\6.4.3_most\nimqt.nim(316, 27) Hint: 'signal_close' is declared but not used [XDeclaredButNotUsed]
E:\TEST\dependencies\nimqt\qt\6.4.3_most\nimqt.nim(316, 27) Hint: 'signal_close' is declared but not used [XDeclaredButNotUsed]
E:\TEST\src\gui\tabwidget.nim(132, 6) Hint: 'create_button' is declared but not used [XDeclaredButNotUsed]
E:\TEST\src\gui\tabwidget.nim(173, 6) Hint: 'set_hover' is declared but not used [XDeclaredButNotUsed]
E:\TEST\src\gui\tabwidget.nim(64, 6) Hint: 'set_selected' is declared but not used [XDeclaredButNotUsed]
E:\TEST\src\gui\tabwidget.nim(19, 8) Warning: imported and not used: 'nimqthelpers' [UnusedImport]
.
E:\TEST\dependencies\nimqt\qt\6.4.3_most\nimqt.nim(316, 27) Hint: 'foo0' is declared but not used [XDeclaredButNotUsed]
E:\TEST\dependencies\nimqt\qt\6.4.3_most\nimqt.nim(70, 25) Warning: imported and not used: 'qstring' [UnusedImport]
.
E:\TEST\src\gui\mainwindow.nim(89, 9) Hint: 'global_signal_handler' is declared but not used [XDeclaredButNotUsed]
E:\TEST\src\gui\mainwindow.nim(8, 8) Warning: imported and not used: 'strutils' [UnusedImport]
E:\TEST\dependencies\nimqt\qt\6.4.3_most\nimqt.nim(72, 24) Warning: imported and not used: 'qevent' [UnusedImport]
E:\TEST\src\exco.nim(24, 16) Warning: imported and not used: 'nimqthelpers' [UnusedImport]
E:\TEST\dependencies\nimqt\qt\6.4.3_most\nimqt.nim(70, 25) Warning: imported and not used: 'qstring' [UnusedImport]
E:\TEST\dependencies\nimqt\qt\6.4.3_most\nimqt.nim(71, 25) Warning: imported and not used: 'qobject' [UnusedImport]
CC: gui/tabwidget.nim
cl : Command line warning D9027 : source file 'shell32.lib' ignored
@mgui@stabwidget.nim.cpp
nimcache\@mgui@stabwidget.nim.cpp(80): error C2061: syntax error: identifier 'string'
nimcache\@mgui@stabwidget.nim.cpp(250): error C2061: syntax error: identifier 'string'
nimcache\@mgui@stabwidget.nim.cpp(263): error C2061: syntax error: identifier 'string'
nimcache\@mgui@stabwidget.nim.cpp(267): error C2761: 'void AdvancedTabBarButton::onclick(void)': redeclaration of member is not allowed
nimcache\@mgui@stabwidget.nim.cpp(267): error C2065: 'string': undeclared identifier
nimcache\@mgui@stabwidget.nim.cpp(267): error C2146: syntax error: missing ')' before identifier 'name'
nimcache\@mgui@stabwidget.nim.cpp(267): error C2143: syntax error: missing ';' before '{'
nimcache\@mgui@stabwidget.nim.cpp(267): error C2447: '{': missing function header (old-style formal list?)
nimcache\@mgui@stabwidget.nim.cpp(410): error C2061: syntax error: identifier 'string'
nimcache\@mgui@stabwidget.nim.cpp(413): error C2065: 'button_p2': undeclared identifier
nimcache\@mgui@stabwidget.nim.cpp(415): error C2065: 'name_p1': undeclared identifier
nimcache\@mgui@stabwidget.nim.cpp(421): error C2065: 'name_p1': undeclared identifier
Error: execution of an external compiler program 'vccexe.exe /c --platform:amd64  /nologo /EHsc -DWIN32_LEAN_AND_MEAN -permissive- -Zc:__cplusplus -std:c++17 -IE:/Qt6/6.3.1/msvc2019_64/include -IE:/Qt6/6.3.1/msvc2019_64/include\QtWidgets -IE:/Qt6/6.3.1/msvc2019_64/include\QtGui -IE:/Qt6/6.3.1/msvc2019_64/include\QtCore -IE:/Qt6/6.3.1/msvc2019_64/include\..\mkspecs\win32-msvc /Zc:strictStrings- shell32.lib -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:throwingNew -Zc:externConstexpr -O2 -MD -utf-8 -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DNDEBUG -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -IC:\Nim\lib -IE:\Qt6\6.3.1\msvc2019_64\include -IE:\Qt6\6.3.1\msvc2019_64\include\QtWidgets -IE:\Qt6\6.3.1\msvc2019_64\include\QtGui -IE:\Qt6\6.3.1\msvc2019_64\include\QtCore -I/include -IE:\Qt6\6.3.1\msvc2019_64\mkspecs\win32-msvc -I.\dependencies\nimqt\qt\6.4.3_most /Zc:strictStrings-   /IC:\Users\...\.choosenim\toolchains\nim-#devel\lib /IE:\TEST\src /nologo /FoE:\TEST\nimcache\@mgui@stabwidget.nim.cpp.obj E:\TEST\nimcache\@mgui@stabwidget.nim.cpp' failed with exit code: 2

stack trace: (most recent call last)
E:\TEST\exco_build.nims(91, 9)
C:\Users\...\.choosenim\toolchains\nim-#devel\lib\system\nimscript.nim(264, 7) exec
C:\Users\...\.choosenim\toolchains\nim-#devel\lib\system\nimscript.nim(264, 7) Error: unhandled exception: FAILED: nim cpp --cc:vcc --outdir:build --mm:orc --nimcache:nimcache --passC:" -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:throwingNew -Zc:externConstexpr -O2 -MD -utf-8 -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DNDEBUG -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -IC:\Nim\lib -IE:\Qt6\6.3.1\msvc2019_64\include -IE:\Qt6\6.3.1\msvc2019_64\include\QtWidgets -IE:\Qt6\6.3.1\msvc2019_64\include\QtGui -IE:\Qt6\6.3.1\msvc2019_64\include\QtCore -I/include -IE:\Qt6\6.3.1\msvc2019_64\mkspecs\win32-msvc -I.\dependencies\nimqt\qt\6.4.3_most /Zc:strictStrings-" --passL:" /NOLOGO /DYNAMICBASE /NXCOMPAT /OPT:REF /OPT:ICF /INCREMENTAL:NO /SUBSYSTEM:CONSOLE " --clib:E:\Qt6\6.3.1\msvc2019_64\lib\Qt6Widgets --clib:E:\Qt6\6.3.1\msvc2019_64\lib\Qt6Gui --clib:E:\Qt6\6.3.1\msvc2019_64\lib\Qt6Core --clib:E:\Qt6\6.3.1\msvc2019_64\lib\Qt6EntryPoint src/exco.nim [OSError]

The problem is in the slot_defer (I tried slot and it's the same), but I don't know why. Any ideas?

jerous86 commented 2 days ago

Hi, an issue I see is that you should use QString instead of string. Does that resolve your issue? If not, can you give me a full MWE (including the imports etc)?

matkuki commented 1 day ago

Here is the code that reproduces the problem:

# Imports
import strformat
import nimqt
import nimqt / [
    qlabel,
    qlayout,
    qboxlayout,
    qgroupbox,
    qtabwidget,
    qdrag,
    qmimedata,
    qvariant,
]

# nimqt initialization
nimqt.init()

## AdvancedTabBarButton
inheritQObject(AdvancedTabBarButton, QGroupBox):
    var name: QString = ""
    var title: QString = ""
    var image_path: QString = ""
    var labels: seq[ptr QLabel] = newSeq()
    var value: bool = false
    var pressed: bool = false
    var dragging: bool = false
    var position_cache: QPoint = newQPoint(-9999.cint, -9999.cint)

    # Signals
    signal signal_click(name: QString, button: int)
    signal signal_close(name: QString)
    signal signal_drag_start()

    # Slots
    slot_defer onclick(name: string, button: Qt_MouseButton):
        if button == Qt_MouseButton.LeftButton:
            if name != "close":
                echo "click"
            elif name == "close":
                echo "close"

nimqt.insertAllSlotImplementations()

an issue I see is that you should use QString instead of string. Does that resolve your issue?

Changing that produces the next problem in the MSVC++ compilation:

nimcache\@merror_reproducing.nim.cpp(60): error C2061: syntax error: identifier 'Qt_MouseButton'

... but why can't I use a string (or bool, or ...) in a slot? Thanks

jerous86 commented 19 hours ago

... but why can't I use a string (or bool, or ...) in a slot?

I think you can use bool etc in a slot. The string is not mapped to std::string, I don't know why. Using QString bypasses that problem (but that would not be a satisfactory solution)

nimcache\@merror_reproducing.nim.cpp(60): error C2061: syntax error: identifier 'Qt_MouseButton'

I also encounter here an issue with Qt_MouseButton: error: unknown type name 'Qt_MouseButton'; did you mean 'Qt::MouseButton?. If I look in qtcore/qnamespace.nim, then I find that Qt_MouseButton* {.header:headerFile,importcpp:"Qt::MouseButton".} = enum ... so I would assume that nim maps Qt_MouseButton to Qt::MouseButton, but maybe due to the macros this does not happen.

Did you encounter this also with earlier compiler versions of nim (or I guess you did not have this code when you were using an older version of nim?)

matkuki commented 11 hours ago

Did you encounter this also with earlier compiler versions of nim (or I guess you did not have this code when you were using an older version of nim?)

Unfortunately no, this is the first time I've used Qt_MouseButton in a slot. Actually, this is the first time I've used slots with arguments.