Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

El mundo es un pañuelo

That's an ex­pres­sion ("The world is a hand­ker­chief") I have of­ten heard, and of­ten found true. It means the world is a very small thing and it's hard for some­thing (or some­one) to get lost in it.

Here are two ex­am­ples:

I went to school with this guy. We were nev­er friends or any­thing. I had com­plete­ly for­got­ten about him. One day, I was walk­ing to the bus stop af­ter teach­ing, and some­one calls me.

It's him. This was rough­ly 15 years af­ter the last time I saw him.

So, we start talk­ing: he worked 2 blocks away from where I did. And 550Km away from our school, and in a 12 mil­lion peo­ple city.

He had lived un­til three weeks be­fore in an apart­ment around the block from my own.

He usu­al­ly went to the same cafe I did, in the cor­ner of our street­s, but he did so 90 min­utes ear­li­er than I did.

And we had nev­er seen each oth­er.

Then we did. On a third place, which was not re­lat­ed to nei­ther of our jobs or home­s.

Sec­ond ex­am­ple:

I met Rosario on May 25th 2004. Ex­cept I al­most met her in 1995 (or so).

I was telling her last night about an af­fair I once had with a girl that lived a ridicu­lous dis­tance away from me (800km or so) and how I had last seen her in a con­gress of the FUA (Ar­genti­na's stu­dents or­ga­ni­za­tion) that took place in San­ta Fe, where I was born.

That con­gress had one par­ty (where I broke up with this girl) in my uni­ver­si­ty's law school.

Well... Rosario was there. I don't re­mem­ber her, but know­ing the place where that par­ty took place, I could not have been the whole night with­out pass­ing 10 feets away from her.

In fac­t, I can't get out of my head a false mem­o­ry of a girl look­ing re­mark­ably like my wife sit­ting on a planter with a wor­ried look in her face (she had had some is­sue that day), with a drink in one hand and a cig­a­rette in the oth­er.

I know I did not see her be­cause I did­n´t re­mem­ber this yes­ter­day, but... I end­ed leav­ing the par­ty with an­oth­er wom­an (o­h, be­ing 24, rash and pret­ty stupid... that wom­an was trou­ble). What would have hap­pened if I did­n't, and start­ed talk­ing with the wom­an sit­ting in the planter?

Where IUP/Qt is right now

It has a de­cent back­end, even if it's lim­it­ed.

Not all wid­gets are im­ple­ment­ed, but they are easy to ad­d. Not all at­tributes are im­ple­ment­ed, but they are even eas­i­er.

And it can show rather com­plex win­dows, too:

http://lateral.blogsite.org/static/diup2.png

Now I remember why I don't like C++

I have refac­tored IUP/Qt in­to a love­ly ob­ject hi­er­ar­chy. And I now re­mem­ber why I dis­like C++.

Here's the ba­sic prob­lem (code may be wrong, I don´t have the bro­ken ver­sions any­more):

I have a base class IOb­jec­t, that has stub set­ter­s/get­ters for all the IUP at­tributes.

For each kind of wid­get, I cre­ate a class that in­her­its from IOb­ject and the match­ing Qt wid­get (ex­am­ple: QDi­alog).

These have to be hooked in­to an Ihan­dle struc­ture through the use of a void * (re­mem­ber, that's C, I have that too ;-)

Now, this was my first naive ap­proach:

Ihandle *n;
IQDialog *d=new IQDialog();
n->handle=d; //handle is a void*

That com­piles ok. How­ev­er, when you try to call a d mem­ber lat­er (and I know I am us­ing old C cast­s... they had worked for me un­til to­day!) ...

((IObject *)(n->handle))set_title("Title here");

Blam­mo, seg­fault. Why? Be­cause in one of the as­sign­ments to/from void *, the point­er for some rea­son starts to point else­where.

Here´s what Glip­tic at #C++ sug­gest­ed, and it does work:

Ihandle *n;
IQDialog *d=new IQDialog();
n->handle=static_cast <void *>(static_cast < IObject *> (d));

Right, I have to cast it twice.

And here is how you get it back:

(static_cast < IObject * >(n->handle))->set_title ("Some title");

Is­n't this just ridicu­lous­ly weird for any­one com­ing from any oth­er lan­guage?

Or am I miss­ing some­thing com­plete­ly?

But the good news is, it works ok, and the Qt back­end now has a de­cent struc­ture to hack on.

IUP/Qt preview

Ok, here is ver­sion 0.0.1 of my Qt4 back­end for IUP . It's not very good, but a bunch of things work. A whole bunch more do not, of course.

I am show­ing this just be­cause I want to re­write it, be­cause I no­ticed that I am writ­ing it like it was Mo­tif stil­l, and I must un­der­stand this is ac­tu­al­ly C++ and Qt code ;-)

Us­ing it along with DI­UP you can write sil­ly Lin­ux/Win­dows/­Mac GUIs from D, or you can use C. No LUA yet.

You can down­load it here (click on the "Free" but­ton and wait a while).

You will need Qt4 and qmake to make it work.


Contents © 2000-2023 Roberto Alsina