Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
QT without c++?
View unanswered posts
View posts from last 24 hours

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2175
Location: $TERM

PostPosted: Thu Apr 04, 2013 3:25 pm    Post subject: QT without c++? Reply with quote

I've been asked to make a GUI which should interface with C code.

Now about my skills:I know C well enough to get the task done, but not C++; I practically have no idea of C++.

Next I need to choose a toolkit for the GUI; one would say GTK+ is the best choice for C, but I was wondering if QT will be a better option but without touching C++ code (or maybe a little bit, like calling functions and using the return values to do simple tasks; but no classes). So can QT be done without C++?

Another point to consider -- I need to do this FAST. I've no time, and developing software is not my job. I won't be maintaining this software either.
_________________
Buy from companies supporting opensource -- IBM, Dell, HP, Hitachi, Google etc...
Disfavor companies supporting only Win -- Logitech, Epson, Adobe, Autodesk, Pioneer, Kingston, WD, Yahoo, MSI, XFX
My blog
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 7774
Location: Somewhere over Atlanta, Georgia

PostPosted: Thu Apr 04, 2013 3:35 pm    Post subject: Reply with quote

See Does Qt have a C interface? over on stackoverflow. :wink:

In my opinion, Qt is a well laid out toolkit and is a better choice for a new project that GTK. Although you must use the C++ compiler, you can program your application in light dialect of C++ that is almost entirely C-like. Furthermore, Qt gives you a better answer to a potential future question, "How much effort to port to Windows or Mac?"

Why don't you run through the tutorials and see what you think?

- John
_________________
This space intentionally left blank.
Back to top
View user's profile Send private message
aCOSwt
Moderator
Moderator


Joined: 19 Oct 2007
Posts: 2537
Location: Hilbert space

PostPosted: Thu Apr 04, 2013 4:13 pm    Post subject: Re: QT without c++? Reply with quote

dE_logics wrote:
I've been asked to make a GUI which should interface with C code.

What kind of interface are you speaking about ?
Do you mean that you would have a gui to display values of variables set by some C code ? To set the value of variables to be used in C code ?
Is the C code modifiable or not ?

Because, well by the way, if the interface is a simple matter of variables then things are not more complicated than declaring them global in the C code and declaring them
Code:
extern "C"
in the C++ code of a qt-gui mainwin.cpp

My advice would be that you use qt-creator / qt-designer for designing your interface (rather intuitive) it will create for you the minimum C++ code needed between which you can insert your C code between the C++ lines or keep the C code in separate files and reference its procedures / variables extern C in your mainwin.cpp.
_________________
Back to top
View user's profile Send private message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2175
Location: $TERM

PostPosted: Thu Apr 04, 2013 6:19 pm    Post subject: Reply with quote

John R. Graham wrote:
See Does Qt have a C interface? over on stackoverflow. :wink:

In my opinion, Qt is a well laid out toolkit and is a better choice for a new project that GTK. Although you must use the C++ compiler, you can program your application in light dialect of C++ that is almost entirely C-like. Furthermore, Qt gives you a better answer to a potential future question, "How much effort to port to Windows or Mac?"

Why don't you run through the tutorials and see what you think?

- John


I did look at that stackoverflow question, as a result I asked if I've to write/understand anything in C++? I've read that C code can be interfaced with QT

The program is practically useless. It's like reinventing the wheel. I'll wipe it off my HDD once the formalities are complete.

Problem with C++ is that I'll have to use C libraries which'll further complicate stuff when compiling. In the mean time I'm already confident with C cause it's simple and I know almost all of it's features.
_________________
Buy from companies supporting opensource -- IBM, Dell, HP, Hitachi, Google etc...
Disfavor companies supporting only Win -- Logitech, Epson, Adobe, Autodesk, Pioneer, Kingston, WD, Yahoo, MSI, XFX
My blog
Back to top
View user's profile Send private message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2175
Location: $TERM

PostPosted: Thu Apr 04, 2013 6:26 pm    Post subject: Re: QT without c++? Reply with quote

aCOSwt wrote:
dE_logics wrote:
I've been asked to make a GUI which should interface with C code.

What kind of interface are you speaking about ?
Do you mean that you would have a gui to display values of variables set by some C code ? To set the value of variables to be used in C code ?
Is the C code modifiable or not ?


Apart from variables, pointers, various return values + I'll be using a lot of misc. C libraries with the C program.

Quote:

Because, well by the way, if the interface is a simple matter of variables then things are not more complicated than declaring them global in the C code and declaring them
Code:
extern "C"
in the C++ code of a qt-gui mainwin.cpp


What about pointers and all (they are built in C++ instead of using stdlib functions)?

I need to have tables, combo box, etc... in the GUI, do I have to deal with a lot of C++?

Quote:
My advice would be that you use qt-creator / qt-designer for designing your interface (rather intuitive) it will create for you the minimum C++ code needed between which you can insert your C code between the C++ lines or keep the C code in separate files and reference its procedures / variables extern C in your mainwin.cpp.


Ok, that mean I've to read the machine generated C++ code.

That pretty much ends it. :(
_________________
Buy from companies supporting opensource -- IBM, Dell, HP, Hitachi, Google etc...
Disfavor companies supporting only Win -- Logitech, Epson, Adobe, Autodesk, Pioneer, Kingston, WD, Yahoo, MSI, XFX
My blog
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 7774
Location: Somewhere over Atlanta, Georgia

PostPosted: Thu Apr 04, 2013 6:33 pm    Post subject: Reply with quote

As aCOSwt alluded to, it's easy to mix C and C++. This is about how much work it is to use C libraries (or C code in general) from C++:
test13a.cpp:
#include <iostream>

extern "C" void Fred(void);

int main(void) {
    std::cout << "Hello, world from C++.\n";

    Fred();

    return 0;
}
test13b.c:
#include <stdio.h>

void Fred(void) {
    printf("Hello, world from C.\n");
}
And to compile and run:
Code:
~ $ gcc -c test13b.c
~ $ g++ test13a.cpp test13b.o -o test13
~ $ ./test13
Hello, world from C++.
Hello, world from C.
:wink:

- John
_________________
This space intentionally left blank.
Back to top
View user's profile Send private message
leo.the_zoo
Tux's lil' helper
Tux's lil' helper


Joined: 04 Jul 2005
Posts: 148
Location: Poland

PostPosted: Thu Apr 04, 2013 6:59 pm    Post subject: Reply with quote

Well, I don't have much experience with qtcreator but I started learning from C++ Builder and as far as I know the philosophy is quite similar. You start a project, design your GUI by adding various objects (labels, text fields, buttons, menus etc.) from a palette of components. The code is generated on the fly. Then what you need to do is to define how the application or the objects should behave on certain event like button click. In Qt you define signals and slots. If the application is a simple one (and it seems to be simple from your description), I believe that if you analyze some simple examples from Qt tutorials, you'll be able to do the job. If you struggle with a problem and cannot find a solution, I guess there are some developers here who know C++ and Qt and would be able to help you.
Back to top
View user's profile Send private message
aCOSwt
Moderator
Moderator


Joined: 19 Oct 2007
Posts: 2537
Location: Hilbert space

PostPosted: Thu Apr 04, 2013 7:15 pm    Post subject: Re: QT without c++? Reply with quote

dE_logics wrote:
I've been asked to make a GUI which should interface with C code.

You want a GUI ? You are free to decide which one ? Everything is useless and will be thrown away in a week-end ?

What about... ncurses ?

OK... there is no builtin function for making a combo-box in a single line but... it won't take many lines to write it in C. (look... alsamixer... F6 select a sound card ! THAT is a combo box !) :twisted:
OK its a bit... Hmmm 1980s looking but it just works with an investment (in learning) considerably lower than learning qt / gtk.

And it... just... works !

Look... Two days ago, I was desperately looking for a simple command to display a text blinking on a qt-gui.
I did not find it and... regretted the good old curses times when this was achievable in a single line of C code !
_________________
Back to top
View user's profile Send private message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2175
Location: $TERM

PostPosted: Fri Apr 05, 2013 5:02 am    Post subject: Reply with quote

Humm.. Ncurses. Never though about that. Thanks for reminding!! I'll ask my project assignee if he likes it.

In the mean time, I've decided to try QT since everyone's really recommending it.
_________________
Buy from companies supporting opensource -- IBM, Dell, HP, Hitachi, Google etc...
Disfavor companies supporting only Win -- Logitech, Epson, Adobe, Autodesk, Pioneer, Kingston, WD, Yahoo, MSI, XFX
My blog
Back to top
View user's profile Send private message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2175
Location: $TERM

PostPosted: Fri Apr 05, 2013 5:26 am    Post subject: Reply with quote

Also I was wondering, how about HTML?
_________________
Buy from companies supporting opensource -- IBM, Dell, HP, Hitachi, Google etc...
Disfavor companies supporting only Win -- Logitech, Epson, Adobe, Autodesk, Pioneer, Kingston, WD, Yahoo, MSI, XFX
My blog
Back to top
View user's profile Send private message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2175
Location: $TERM

PostPosted: Fri Apr 05, 2013 7:26 am    Post subject: Reply with quote

Nope, it's final. GTK+ (glade), cause the button clicking Bill Gates Labradors want click able buttons and all should be in C.
_________________
Buy from companies supporting opensource -- IBM, Dell, HP, Hitachi, Google etc...
Disfavor companies supporting only Win -- Logitech, Epson, Adobe, Autodesk, Pioneer, Kingston, WD, Yahoo, MSI, XFX
My blog
Back to top
View user's profile Send private message
aCOSwt
Moderator
Moderator


Joined: 19 Oct 2007
Posts: 2537
Location: Hilbert space

PostPosted: Fri Apr 05, 2013 9:04 am    Post subject: Reply with quote

dE_logics wrote:
cause the button clicking Bill Gates Labradors want click able buttons and all should be in C.

:lol:
Well, I understand that it is needless to argue then...

Depending on your position, their level of humour... you might then try to educate them a bit with a " :roll: :roll: curses is all C and it is and possible and just easy to capture mouse clicks thanks to the curses lib"
You can eventually... depending on the conditions stated above add :
"Hopefully the guys at Berkeley did not wait for Bill Gates to discover and answer all the needs of a real GUI" + optional :P ad libitum.

:wink:

4.4 BSD curses +terminfo rocked ! I never met anyone unpleased with the results and I make no doubt that it still exactly fits for purpose in contemporary applications for embedded systems.
_________________
Back to top
View user's profile Send private message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2175
Location: $TERM

PostPosted: Fri Apr 05, 2013 1:53 pm    Post subject: Reply with quote

Oh, you know he wants a 'window'.

He doesn't seem to know what a toolkit is. All he knows is .NET. And in that I doubt if he knows even c# cause I know he doesn't know C++ well.

Actually I should take his decision as a bonus. He actually allowed me to NOT use Microsoft technology and made it optional to code for Windows.
_________________
Buy from companies supporting opensource -- IBM, Dell, HP, Hitachi, Google etc...
Disfavor companies supporting only Win -- Logitech, Epson, Adobe, Autodesk, Pioneer, Kingston, WD, Yahoo, MSI, XFX
My blog
Back to top
View user's profile Send private message
yngwin
Developer
Developer


Joined: 19 Dec 2002
Posts: 4394
Location: Suzhou, China

PostPosted: Fri Apr 05, 2013 3:48 pm    Post subject: Reply with quote

If it's just the GUI frontend I would recommend PyQt4.
_________________
"Those who deny freedom to others deserve it not for themselves." - Abraham Lincoln
Free Culture | Defective by Design | EFF
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 7774
Location: Somewhere over Atlanta, Georgia

PostPosted: Tue Apr 09, 2013 8:59 pm    Post subject: Reply with quote

For use with C? :roll:

- John
_________________
This space intentionally left blank.
Back to top
View user's profile Send private message
ulenrich
Veteran
Veteran


Joined: 10 Oct 2010
Posts: 1155

PostPosted: Tue Apr 09, 2013 9:48 pm    Post subject: Reply with quote

John R. Graham wrote:
And to compile and run:
Code:
~ $ gcc -c test13b.c
~ $ g++ test13a.cpp test13b.o -o test13
~ $ ./test13
Hello, world from C++.
Hello, world from C.
:wink:

This way using a compiler no c code will be left, only machine code will interact!
_________________
fun2gen2
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 7774
Location: Somewhere over Atlanta, Georgia

PostPosted: Tue Apr 09, 2013 10:27 pm    Post subject: Reply with quote

As opposed to the normal way you use C and C++ without a compiler? :wink:

- John
_________________
This space intentionally left blank.
Back to top
View user's profile Send private message
ulenrich
Veteran
Veteran


Joined: 10 Oct 2010
Posts: 1155

PostPosted: Tue Apr 09, 2013 10:55 pm    Post subject: Re: QT without c++? Reply with quote

dE_logics wrote:
I've been asked to make a GUI which should interface with C code.

First came into mind to use a C interpreter. But you never know: Under the hood the interpreter might translate the C code into machine code ...

... I doubt there is a cpu available yet which can run C code directly. Perhaps the task is to develop a special quantum computing gadget?
_________________
fun2gen2
Back to top
View user's profile Send private message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2175
Location: $TERM

PostPosted: Sat Apr 13, 2013 4:18 pm    Post subject: Re: QT without c++? Reply with quote

ulenrich wrote:
dE_logics wrote:
I've been asked to make a GUI which should interface with C code.

First came into mind to use a C interpreter. But you never know: Under the hood the interpreter might translate the C code into machine code ...

... I doubt there is a cpu available yet which can run C code directly. Perhaps the task is to develop a special quantum computing gadget?


There's no CPU till date which can run as any kind of interpreter. All interpreters translate scripting languages to machine code and get it run directly on the CPU; actually, the interpreter gets the task done by a language which can be compiled into native code.
_________________
Buy from companies supporting opensource -- IBM, Dell, HP, Hitachi, Google etc...
Disfavor companies supporting only Win -- Logitech, Epson, Adobe, Autodesk, Pioneer, Kingston, WD, Yahoo, MSI, XFX
My blog
Back to top
View user's profile Send private message
wolfieh
n00b
n00b


Joined: 17 Nov 2009
Posts: 52

PostPosted: Sat Apr 13, 2013 5:41 pm    Post subject: Reply with quote

you can always use the C subset of C++ for your application. If you need non-mangled symbols you can use extern "C" { ... } and it will give C ABI.
Qt is written in C++ with extensions (moc, "meta object compiler") so at least the code that interfaces with the library must be in C++. Maybe someone made pure C bindings but don't know. Your best bet is to use GTK, since it's written in pure C
Back to top
View user's profile Send private message
i92guboj
Moderator
Moderator


Joined: 30 Nov 2004
Posts: 9844
Location: Córdoba (Spain)

PostPosted: Sat Apr 13, 2013 6:11 pm    Post subject: Reply with quote

Ugh...

But QT anyway is almost an entirely different animal than C++. You will work with signals and slots... Knowing C++ doesn't grant you any knowledge about QT, unless "you are doing it the wrong way (tm)". In fact, I know some people that learnt QT without any previous C++ knowledge. Your only contact with C++ will be when compiling :lol:

There are bindings for many languages, though, for those that are picky about having to write a couple of keywords here and there :lol:

http://qt-project.org/wiki/Category:LanguageBindings
_________________
Gentoo Handbook | My website
Back to top
View user's profile Send private message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2175
Location: $TERM

PostPosted: Mon Apr 15, 2013 7:13 pm    Post subject: Reply with quote

^^

You mean if you're using a designer or something.

For e.g. in GTK I'm using glade; that way I wont need to know GTK completely, just the concepts like containers, widgets, treeeview, viewport etc...
_________________
Buy from companies supporting opensource -- IBM, Dell, HP, Hitachi, Google etc...
Disfavor companies supporting only Win -- Logitech, Epson, Adobe, Autodesk, Pioneer, Kingston, WD, Yahoo, MSI, XFX
My blog
Back to top
View user's profile Send private message
i92guboj
Moderator
Moderator


Joined: 30 Nov 2004
Posts: 9844
Location: Córdoba (Spain)

PostPosted: Mon Apr 15, 2013 7:37 pm    Post subject: Reply with quote

No, I mean what I wrote :lol:

You need to know the basics of the grammar and syntax, but... qt is not c++. At least not in the way that, let's say, sdl is c. I know this is a bit subjective, but i am not too fond on qtdesigner or glade. The best ide ever is bluefish.
_________________
Gentoo Handbook | My website
Back to top
View user's profile Send private message
lost+found
Guru
Guru


Joined: 15 Nov 2004
Posts: 412
Location: North~Sea~Coa~s~~t~~~

PostPosted: Tue Apr 16, 2013 7:28 am    Post subject: Reply with quote

GNUstep has a fast gui designer. C is a subset of Objective-C.
Back to top
View user's profile Send private message
dE_logics
Advocate
Advocate


Joined: 02 Jan 2009
Posts: 2175
Location: $TERM

PostPosted: Fri Apr 19, 2013 5:25 pm    Post subject: Reply with quote

i92guboj wrote:
No, I mean what I wrote :lol:

You need to know the basics of the grammar and syntax, but... qt is not c++. At least not in the way that, let's say, sdl is c. I know this is a bit subjective, but i am not too fond on qtdesigner or glade. The best ide ever is bluefish.


But QT now supports c++0x, that's a standard. So it does use C++.

@lost+found

Only C.
_________________
Buy from companies supporting opensource -- IBM, Dell, HP, Hitachi, Google etc...
Disfavor companies supporting only Win -- Logitech, Epson, Adobe, Autodesk, Pioneer, Kingston, WD, Yahoo, MSI, XFX
My blog
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum