[Qt-jambi-interest] Overriding itemChange() crashes the VM in 4.4.0_01

2008-07-08 Thread Mika Halttunen
Hi,
this is probably related to 
http://trolltech.com/developer/task-tracker/index_html?method=entryid=215908, 
but I though I'd give additional information about this.

I have VertexItems (based on QGraphicsItem) and PolygonItems (based on 
QGraphicsPolygonItem). PolygonItems should have VertexItems as children, 
so when I move a polygon it's vertices would also move.

I'm setting up the PolygonItem from my own Polygon class like this:

public void setMyPolygon(Polygon poly) {
this.polygon = poly;
this.color = new QColor(poly.getColor().getRed(), 
poly.getColor().getGreen(), poly.getColor().getBlue(), 
poly.getColor().getAlpha());

setBrush(new QBrush(color));
setPen(VertexItem.blackPen);

// Create the Qt polygon
QPolygonF qPoly = new QPolygonF();
// Add the vertices
for (Vertex v : poly.getVertices()) {
qPoly.add(v.position.x, v.position.y);

// Add them as children VertexItems
VertexItem vItem = new VertexItem(v);
vItem.setParentItem(this); / --- CRASHES HERE!
}

setPolygon(qPoly);
}

The line vItem.setParentItem(this) causes the crash. That occurs only
when either VertexItem and/or PolygonItem have overridden itemChange().

Even when I just supply the default implementation, it will crash. For 
example, on VertexItem:

@Override
public Object itemChange(GraphicsItemChange change, Object value) {
return super.itemChange(change, value);
}


So the bottom line is, itemChange() can be overridden when the items are 
not in any kind of parent/child relationship.

Unfortunately, I cannot continue my project too far without this being 
fixed. :( Hopefully you get it resolved for the next Qt Jambi update. Is 
there any work arounds for this? I'd really need to know when the 
Vertex/Polygon item positions change..

Anyways, thanks for the great work on Qt + Qt Jambi! :)

--
Mika
___
Qt-jambi-interest mailing list
Qt-jambi-interest@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest


Re: [Qt-jambi-interest] Jambi and JNI Integration

2008-07-08 Thread Eskil Abrahamsen Blomfeldt
Adam Batkin wrote:
 Anyway, I've now set out to write my own JNI code to do what I want, instead 
 of using the 
 Jambi Generator. Everything was working nicely until trying to transfer a 
 QImage from C++ 
 to a Java/Jambi QImage. Back in February, Gunnar suggested stealing some 
 logic from the 
 generated Jambi code, in particular QPixmap::toImage():
  jobject jimg =
  qtjambi_from_object(env,
  image,
  QImage,
  com/trolltech/qt/gui/,
  true);

 This works -- almost. I get back a valid Java QImage object 
 (System.err.println(image) 
 prints something like [EMAIL PROTECTED]) but when I try to do anything 
 with it (like call image.width()), the JVM crashes.
   

Hi, Adam.

Has Qt Jambi been properly initialized at this point? I.e. you need to 
initialize each of the libraries you use before they can be used, 
otherwise Qt Jambi won't know e.g. that it has to copy the QImage into a 
new object before linking it into a Java object, and you will get a Java 
object with a pointer into the stack. The initialization of Qt Jambi 
libraries is done the first time a class from the library is loaded by 
the virtual machine. In your case, I think you are calling the 
conversion code before loading any Jambi GUI classes. The conversion 
code itself will resolve and load the QImage class, thus initializing 
the GUI library, but unfortunately this is too late for the first 
conversion, and the first Java object you retrieve will contain a 
pointer to the object you allocated on stack. This is why you can fix 
the problem by manually loading the class using the resolveClass() call, 
or by calling another method which causes the library to be initialized.

We can easily fix this particular problem by moving some code around, 
and I'll make a suggestion to do so. However, I'm not convinced that 
we'll be able to fix all related issues, so I recommend you initialize 
the library prior to using Qt Jambi. For instance, we don't support 
having Qt Jambi application that have not called 
QApplication.initialize() or QCoreApplication.initialize() (the former 
in your case.) If you call QApplication.initialize() in the beginning of 
your application, this should cause the GUI library to be initialized.

-- Eskil


___
Qt-jambi-interest mailing list
Qt-jambi-interest@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest


[Qt-jambi-interest] Using .jui files with custom widget needing personal library crashes Eclipse

2008-07-08 Thread moebius
Hi people,

I developed my own library called dgl (pure java, no jambi here). Once
this library packaged into a jar, I used it to develop my own jambi widget
called Plotter. Until then all is working fine. The first problem arise
when I want to include this widget into the jambi designer integrated in
Eclipse. The plugin refuse to load as long as the Plotter constructor
included a dgl object. To workaround this, I create an empty constructor
and also create other functions to manage dgl objects. OK, then I can see
my newly created Qt designer plugin in project properties panel.
But at this point when I tried to open a .jui file, Eclipse crashes
systematically. Here is the beginning of the error log :

Exception in thread main java.lang.NoClassDefFoundError: org/lgmt/dgl/Curve
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
at java.lang.Class.getDeclaredMethods(Class.java:1791)
at
com.trolltech.qt.internal.MetaObjectTools.buildMetaData(MetaObjectTools.java:405)
at
com.trolltech.qt.gui.QWidget.__qt_QWidget_QWidget_WindowFlags(Native
Method)
at com.trolltech.qt.gui.QWidget.init(QWidget.java:77)
at com.trolltech.qt.gui.QWidget.init(QWidget.java:69)
at org.lgmt.jasp.plotter.Plotter.init(Plotter.java:45)
snip

I precise that of course my dgl.jar file including not found Curve
object is in libraries build path.

So my question is : is there special requirements to make a qt designer
plugin ? How to make a plugin that can deal with an external object ? How
to modify my own library to avoid this crash ?

Thanks for any help...

jMax



___
Qt-jambi-interest mailing list
Qt-jambi-interest@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest


Re: [Qt-jambi-interest] Jambi and JNI Integration

2008-07-08 Thread Adam Batkin
Initializing my QApplication first does in fact solve the problem. I'm not sure 
how I 
missed that (*smacks forehead*). Mostly because I was doing this in a 4-line 
test harness 
and not an actual program (which would of course have initialized QT since 
using QT Jambi 
is the whole point of this exercise!)

You mentioned being able to move some code around to fix this particular issue 
but that 
wouldn't be a general fix; I would say that even better (if possible) would be 
to warn 
that you have to initialize QT first. I mention this because some classes do in 
fact print 
warnings if you try to use them without initializing QT first (for example when 
I was 
testing and I created an empty QPixmap, it yelled at me). In other words, what 
I did was 
wrong, but it would have been helpful to get a warning or something (since JVM 
crashes 
aren't the easiest things to debug)

Anyway, thanks for the help!

-Adam Batkin

Eskil Abrahamsen Blomfeldt wrote:
 Adam Batkin wrote:
 Anyway, I've now set out to write my own JNI code to do what I want, 
 instead of using the Jambi Generator. Everything was working nicely 
 until trying to transfer a QImage from C++ to a Java/Jambi QImage. 
 Back in February, Gunnar suggested stealing some logic from the 
 generated Jambi code, in particular QPixmap::toImage():
  jobject jimg =
  qtjambi_from_object(env,
  image,
  QImage,
  com/trolltech/qt/gui/,
  true);

 This works -- almost. I get back a valid Java QImage object 
 (System.err.println(image) prints something like 
 [EMAIL PROTECTED]) but when I try to do anything with 
 it (like call image.width()), the JVM crashes.
   
 
 Hi, Adam.
 
 Has Qt Jambi been properly initialized at this point? I.e. you need to 
 initialize each of the libraries you use before they can be used, 
 otherwise Qt Jambi won't know e.g. that it has to copy the QImage into a 
 new object before linking it into a Java object, and you will get a Java 
 object with a pointer into the stack. The initialization of Qt Jambi 
 libraries is done the first time a class from the library is loaded by 
 the virtual machine. In your case, I think you are calling the 
 conversion code before loading any Jambi GUI classes. The conversion 
 code itself will resolve and load the QImage class, thus initializing 
 the GUI library, but unfortunately this is too late for the first 
 conversion, and the first Java object you retrieve will contain a 
 pointer to the object you allocated on stack. This is why you can fix 
 the problem by manually loading the class using the resolveClass() call, 
 or by calling another method which causes the library to be initialized.
 
 We can easily fix this particular problem by moving some code around, 
 and I'll make a suggestion to do so. However, I'm not convinced that 
 we'll be able to fix all related issues, so I recommend you initialize 
 the library prior to using Qt Jambi. For instance, we don't support 
 having Qt Jambi application that have not called 
 QApplication.initialize() or QCoreApplication.initialize() (the former 
 in your case.) If you call QApplication.initialize() in the beginning of 
 your application, this should cause the GUI library to be initialized.
 
 -- Eskil
 
 

___
Qt-jambi-interest mailing list
Qt-jambi-interest@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest


[Qt-jambi-interest] [Bug] JUIC broken with ScrollArea

2008-07-08 Thread Jose Arcangel Salazar Delgado
Hi
I found a bug in the JUIC. The problem is when you try to use a scroll
area in a form. The preview is ok, but when you exec the app with the
Ui file, the scroll area is empty. After a few research I encounter
the problem, look at this code:

/
** Form generated from reading ui file 'MainWindow.jui'
**
** Created: mi jul 9 00:24:23 2008
**  by: Qt User Interface Compiler version 4.4.0
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
/

import com.trolltech.qt.core.*;
import com.trolltech.qt.gui.*;

public class Ui_MainWindow
{
public QWidget centralwidget;
public QGridLayout gridLayout;
public QScrollArea scrollArea;
public QWidget scrollAreaWidgetContents;
public QPushButton pushButton;
public QMenuBar menubar;
public QStatusBar statusbar;

public Ui_MainWindow() { super(); }

public void setupUi(QMainWindow Ui_MainWindow)
{
Ui_MainWindow.setObjectName(Ui_MainWindow);
Ui_MainWindow.resize(new QSize(800,
600).expandedTo(Ui_MainWindow.minimumSizeHint()));
centralwidget = new QWidget(Ui_MainWindow);
centralwidget.setObjectName(centralwidget);
centralwidget.setGeometry(new QRect(0, 30, 800, 547));
gridLayout = new QGridLayout(centralwidget);
gridLayout.setObjectName(gridLayout);
scrollArea = new QScrollArea(centralwidget);
scrollArea.setObjectName(scrollArea);
scrollArea.setWidgetResizable(true);
scrollAreaWidgetContents = new QWidget();
scrollAreaWidgetContents.setObjectName(scrollAreaWidgetContents);
scrollAreaWidgetContents.setGeometry(new QRect(0, 0, 778, 525));
pushButton = new QPushButton(scrollAreaWidgetContents);
pushButton.setObjectName(pushButton);
pushButton.setGeometry(new QRect(200, 160, 75, 28));

pushButton.setFocusPolicy(com.trolltech.qt.core.Qt.FocusPolicy.StrongFocus);

gridLayout.addWidget(scrollArea, 0, 0, 1, 1);

Ui_MainWindow.setCentralWidget(centralwidget);
menubar = new QMenuBar(Ui_MainWindow);
menubar.setObjectName(menubar);
menubar.setGeometry(new QRect(0, 0, 800, 30));
Ui_MainWindow.setMenuBar(menubar);
statusbar = new QStatusBar(Ui_MainWindow);
statusbar.setObjectName(statusbar);
statusbar.setGeometry(new QRect(0, 577, 800, 23));
Ui_MainWindow.setStatusBar(statusbar);
retranslateUi(Ui_MainWindow);

Ui_MainWindow.connectSlotsByName();
} // setupUi

void retranslateUi(QMainWindow Ui_MainWindow)
{

Ui_MainWindow.setWindowTitle(com.trolltech.qt.core.QCoreApplication.translate(Ui_MainWindow,
MainWindow));

pushButton.setText(com.trolltech.qt.core.QCoreApplication.translate(Ui_MainWindow,
PushButton));
} // retranslateUi

}

The problem is that the scrollAreaWidgetContents is never set the
widget of scrollArea.
For now Im using this workaround in the MainWindow class:

/*main class*/
import com.trolltech.qt.gui.*;

public class MainWindow extends QMainWindow {

Ui_MainWindow ui = new Ui_MainWindow();

public static void main(String[] args) {
QApplication.initialize(args);

MainWindow testMainWindow = new MainWindow();

testMainWindow.ui.scrollArea.setWidget(testMainWindow.ui.scrollAreaWidgetContents);
testMainWindow.show();


QApplication.exec();
}

public MainWindow() {
ui.setupUi(this);
}

}

This problem is experiment in windows and linux using the lastest qt
eclipse integration and the lastest QT jambi (4.4.0).

Thanks for your good work.
___
Qt-jambi-interest mailing list
Qt-jambi-interest@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest