-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
juic & signal slot in QtJambi 5.15.2 #17
Comments
Hi. There is no longer a jui tool. I dropped this from the project because it was not maintained for over 10 years and I was not able to get this code running with Qt5 in a reasonable amount of time. Additionally, jui needed a patched version of designer because it did not work with ui files but with jui files specific for Java. Both tools were way too outdated to bring them to newest Qt versions. Maybe in the future, I will develop it again from scratch but unclear. I assumed working with UI files has been gradually replaced by QML. UI files can be loaded by |
All right. I did not see TestUiTools.java. Can you tell me where he is? In addition, there is no QUiLoader class. There is. I used qml and java. But when looking up an object in qml, it always returns null. Why? The content of App.java is as follows: public class App
{
public static void main(String[] args)
{
QGuiApplication.initialize(args);
QtUtilities.initializePackage("io.qt.quick");
QQmlApplicationEngine engine = new QQmlApplicationEngine();
engine.load(QUrl.fromClassPath("main.qml"));
QLabel label02 = engine.rootObjects().first().findChild(QLabel.class, "label02");
System.out.println(label02); // return is null why?
QGuiApplication.exec();
QGuiApplication.shutdown();
}
} The content of main.qml is as follows import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
Window
{
width: 640
height: 480
visible: true
title: qsTr("Hello World")
Label
{
objectName: "label02"
text: "QML AND CPP 02"
font.pixelSize: 22
color: "#00C20C"
y: 20
function getText(name)
{
return text + name
}
}
} |
Oh, I see, |
Regarding your qml example: I never used Following tests deal with QML, maybe you could learn from it:
|
Oh, no, now I see the mistake: QML type QQuickItem label02 = engine.rootObjects().first().findChild(QQuickItem.class, "label02"); ...should fix it. |
I found the problem. In another project, the traditional widget approach In addition, QMetaObject.invokeMethod(label02, "getText", "ITSweets") throws an exception "main" io.qt.QNoSuchMethodException: Method not found: getText The method of calling qml components here is also different from c++? I prepared for a while and I was almost done, recording a set of tutorials. Because the tutorials on this framework in China are still Qt4 around 2014. I don't want such an excellent framework to be buried. After all, it is based on the powerful Qt |
|
QUrl("file:/:classpath:main.qml") cannot get the object in this way, but the form can be displayed normally. very strange. correct |
Maybe you should make yourself familiar with available methods in label02:
|
Ok, maybe its rather QUrl("file:///:classpath:main.qml") |
I don't understand what you are doing causing the exception. Can you give me more code? |
This is my code QObject.connect(button_cancel.clicked, APPWidget.callback());
QObject.connect(button_cancel.clicked, APPWidget::fun02); A processing function is added for button clicks, in the form of APPWidget.callback() The corresponding function implementations are public static QMetaObject.Slot0 callback()
{
return new QMetaObject.Slot0()
{
@Override
public void invoke() throws Throwable
{
System.out.println("callback");
}
};
} The above is very troublesome, is there no implementation class of QMetaObject.Slot0 interface? Even lambda is just a little bit simpler. |
After printing the method name of the object in qml to the console, it is found that there is indeed this method.
Using Object getText1 = QMetaObject.invokeMethod(label02, "getText(QVariant)", "ITSweets"); Executing this method will throw the following exception. Obviously there are, so strange. Is the parameter passing way wrong?
Exception in thread "main" io.qt.QNoSuchMethodException: Method not found: getText(QVariant) If the method in qml is getText() without parameters, use |
The only reason for So, make a connection like this: QObject.connect(button_cancel.clicked, APPWidget::fun02);
QObject.connect(button_cancel.clicked, clicked -> { APPWidget.fun02(); }); However, custom implementations of |
what happens if you use Java method signature: You could also do this in two steps: object.metaObject.method("getText", Object.class).invoke(...); |
The dynamic loading of the .ui file just mentioned, then if you want to rewrite some events of the dynamically loaded form (such as closeEvent, eventFilter, etc.) how to achieve it. There is no idea. |
I believe there is no way to override methods from your UI-defined objects because there is no class generation. You could define custom subclasses of certain widget types with your intended overridden methods and then use these types in UI form. |
The result of using getText(Object) and getText(QObject) is the same as getText(QVariant). Is this not feasible? |
I have seen many .jui files in your source code. Did you also use the juic.exe of Qt 4.x to generate it? I think you should develop juic. He is very important. Or what method did you use to generate .jui? |
QObject is definitely wrong because QObject is not QVariant. Object (without Q) is the top level Java class type. However, I will check out if there is a bug in QtJambi. |
Before 2009, QtJambi project was developed by the makers of Qt. There is a lot of old code in the project I don't care about. Especially the examples are totally outdated for over a decade. They don't work at all. Maybe, I should drop them from the project. |
So will you always maintain this project? |
I do since 2009 and I will continue. |
I checked your code example and I don't get any errors here: QByteArray data = new QByteArray("import QtQuick 2.15\n" +
"Item {\n" +
" function test(s){console.info(s)}\n" +
"}");
QQmlApplicationEngine engine = new QQmlApplicationEngine();
engine.loadData(data);
QObject object = engine.rootObjects().first();
QMetaObject.invokeMethod(object, "test(java.lang.Object)", "TEST1");
QMetaObject.invokeMethod(object, "test(Object)", "TEST2");
QMetaObject.invokeMethod(object, "test(QVariant)", "TEST3"); Resulting in outprint:
|
In my case, only |
In order to further your understanding, I recorded a few seconds of video. |
It was not easy to see the whole video because it buffers all the time. I think I got it. Can you debug through these lines step by step? Is it Application.exec() never returning but resulting in a crash? Is it actually a crash? Java crashes look different from that. What Java are you using? |
I am using QGuiApplication.exec(); |
I watched it again. Actually, it did not crash. You terminated the program in your IDE. So, what's your question with the video? Maybe, I did not understand. |
That is, |
Ah, ok. I see. So, I am using a revised version of QtJambi which I will publish shortly. There, it is possible to use it in different ways:
All suitable to call a QML defined function "test" with variant argument. |
Hi, I'm here again. Is the patch version of Qt 5.15.2 updated? It's about the parameters of the signal slot. Does this problem also exist in Qt 6? Qt seems to have been updated to Qt 6.2.2. |
Hi. I don't understand your question. As far as I see, version 5.15.2 and 6.2.2 are the latest available open source releases of Qt. Qtjambi got a patch update. Here, the versions are 5.15.3 and 6.2.1 (first and second number refer to Qt and the third number is the QtJambi release). In QtJambi 5.15.3 and 6.2.1 the solution mentioned above is realized. |
Okay, blame me for not expressing clearly. This is your last reply. This is the problem I just mentioned. Ah, ok. I see. So, I am using a revised version of QtJambi which I will publish shortly. There, it is possible to use it in different ways: QMetaObject.invokeMethod(object, "test(java.lang.Object)", "TEST1"); I saw that you released a new version two days ago, but I did not find the download link of qtjambi 5.15.3 on the re-release page. Is it a link to qtjambi 5.15.2? |
You should follow the instructions under QtJambi modules. |
UIC tool now available as module qtjambi.uic. |
Hi. I want to learn this framework. But in the java binding in Qt5.15.2, I did not see the tool (jui.exe) to convert .ui files. How should it be converted? In addition, there are links between signals and slots. Are there any sample programs? All on the Internet are version 4.x. Looking forward to your reply.
The text was updated successfully, but these errors were encountered: