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):
OS: Windows 10
Java version OpenJDK 17
Kotlin version 1.8.0
QtJambi version 5.15.13
Qt version 5.15.5
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:
The converted kt code has many errors in loose syntax calls, which are checked out by Intelij IDEA, resulting in unsmooth compilation, such as
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
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
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")
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:
The converted kt code has many errors in loose syntax calls, which are checked out by Intelij IDEA, resulting in unsmooth compilation, such as
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
Based on the first question, manually fix the errors and warnings. Then compile, and an exception occurs at compile time:
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