Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIC to Kotlin errors and exceptions #129

Closed
ITSweets opened this issue Jan 25, 2023 · 1 comment
Closed

UIC to Kotlin errors and exceptions #129

ITSweets opened this issue Jan 25, 2023 · 1 comment

Comments

@ITSweets
Copy link

ITSweets commented Jan 25, 2023

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:

  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

  1. 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 added a commit that referenced this issue Mar 18, 2023
#135 Decreasing UI performance of QListView
#129 UIC to Kotlin errors and exceptions
#139 Does qtJambi work also for STM32MP1?
#130 How to use QtJambi Generator to create Java bindings to Qt C++ dependency library
@omix
Copy link
Contributor

omix commented Mar 20, 2023

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

  • nullness of parameters
  • operator overloading
  • Kotlin-style properties
  • improved UIC

@omix omix closed this as completed Mar 20, 2023
omix added a commit that referenced this issue Jul 25, 2023
#135 Decreasing UI performance of QListView
#129 UIC to Kotlin errors and exceptions
#139 Does qtJambi work also for STM32MP1?
#130 How to use QtJambi Generator to create Java bindings to Qt C++ dependency library
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants