OmixVisualization / qtjambi

QtJambi is a wrapper for using Qt in Java.
http://www.qtjambi.io
Other
365 stars 43 forks source link

UIC to Kotlin errors and exceptions #129

Closed ITSweets closed 1 year ago

ITSweets commented 1 year ago

Describe the bug The KT code after the UIC converts the UI file to Kotlin has errors and loose syntax, and the compilation fails because the structure is not good enough

Expected behavior uic to kotlin code, the language is rigorous without errors, preferably in Intellij IDEA without warnings. The setup method is optimized and does not cause exceptions

System (please complete the following information):

Additional context Hi, this should be the first question there is about uic and kotlin. Seeing that UIC already supports Kotlin, I played around for a while. I found a lot of problems though. It is listed below:

  1. The converted kt code has many errors in loose syntax calls, which are checked out by Intelij IDEA, resulting in unsmooth compilation, such as

        this.horizontalLayout_8 = QHBoxLayout(this.widget_10)
        this.horizontalLayout_8.setSpacing(10)  
        this.horizontalLayout_8?. setObjectName("horizontalLayout_8")

    The second statement results in an error because there is no ? No, this must be an oversight, because there are other methods of the same instance? Invoke. Not only the layout, but also the method calls of many controls have this problem, and I can't give you a list of exactly which controls have them because my UI doesn't use all the Qt controls

  2. Based on the first question, manually fix the errors and warnings. Then compile, and an exception occurs at compile time:

Caused by: org.jetbrains.org.objectweb.asm.MethodTooLargeException: Method too large: Ui_HeraBasic.setupUi (Lio/qt/widgets/QWidget;) V

java.lang.RuntimeException: Error generating class file Ui_HeraBasic.class (compiled from [D:IdeaProjectsaDrive-HerasrcmainkotlinUi_HeraBasic.kt]): Method too large: Ui_ HeraBasic.setupUi (Lio/qt/widgets/QWidget;)V 

Obviously kotlin has some detection, here triggers the restriction that the method body is too long, should the setup method be taken apart? For example, if there are more than a number of child controls in a control, extract a method separately, and then call it in setup. Or some other method. At present, my program has just developed the converted KT UI code 3700+ lines. I mean 3700 lines of code have these problems. If there are more, this is very necessary to solve.

Finally, a screenshot is attached to you to give you a quick idea of what the problem is

Snipaste_2023-01-25_11-24-42.png Snipaste_2023-01-25_11-25-53.png Snipaste_2023-01-25_11-27-28.png Snipaste_2023-01-25_11-27-28.png

To add, there is another error: the code block that starts setup will also report an error that the compilation will not pass. Modify the following code according to the IDE prompts to compile and pass. By the way, the method body is too long, and I extracted the submethods to make the setup method body smaller and the program run normally

    fun setupUi(heraBasic: QWidget){

        if (heraBasic?.objectName().isEmpty())
            heraBasic?.setObjectName("HeraBasic")

    fun setupUi(heraBasic: QWidget){
        // updated
        if (heraBasic?.objectName()?.isEmpty() == true)
            heraBasic?.setObjectName("HeraBasic")
omix commented 1 year ago

Take a look at improved Kotlin support of latest release including: