View previous topic :: View next topic |
Author |
Message |
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Thu Apr 04, 2013 3:25 pm Post subject: QT without c++? |
|
|
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. _________________ My blog |
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10587 Location: Somewhere over Atlanta, Georgia
|
Posted: Thu Apr 04, 2013 3:35 pm Post subject: |
|
|
See Does Qt have a C interface? over on stackoverflow.
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 can confirm that I have received between 0 and 499 National Security Letters. |
|
Back to top |
|
|
aCOSwt Bodhisattva
Joined: 19 Oct 2007 Posts: 2537 Location: Hilbert space
|
Posted: Thu Apr 04, 2013 4:13 pm Post subject: Re: QT without c++? |
|
|
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 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 |
|
|
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Thu Apr 04, 2013 6:19 pm Post subject: |
|
|
John R. Graham wrote: | See Does Qt have a C interface? over on stackoverflow.
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. _________________ My blog |
|
Back to top |
|
|
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Thu Apr 04, 2013 6:26 pm Post subject: Re: QT without c++? |
|
|
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 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. _________________ My blog |
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10587 Location: Somewhere over Atlanta, Georgia
|
Posted: Thu Apr 04, 2013 6:33 pm Post subject: |
|
|
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. |
- John _________________ I can confirm that I have received between 0 and 499 National Security Letters. |
|
Back to top |
|
|
leo.the_zoo Apprentice
Joined: 04 Jul 2005 Posts: 160 Location: Poland
|
Posted: Thu Apr 04, 2013 6:59 pm Post subject: |
|
|
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 |
|
|
aCOSwt Bodhisattva
Joined: 19 Oct 2007 Posts: 2537 Location: Hilbert space
|
Posted: Thu Apr 04, 2013 7:15 pm Post subject: Re: QT without c++? |
|
|
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 !)
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 |
|
|
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Fri Apr 05, 2013 5:02 am Post subject: |
|
|
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. _________________ My blog |
|
Back to top |
|
|
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Fri Apr 05, 2013 5:26 am Post subject: |
|
|
Also I was wondering, how about HTML? _________________ My blog |
|
Back to top |
|
|
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Fri Apr 05, 2013 7:26 am Post subject: |
|
|
Nope, it's final. GTK+ (glade), cause the button clicking Bill Gates Labradors want click able buttons and all should be in C. _________________ My blog |
|
Back to top |
|
|
aCOSwt Bodhisattva
Joined: 19 Oct 2007 Posts: 2537 Location: Hilbert space
|
Posted: Fri Apr 05, 2013 9:04 am Post subject: |
|
|
dE_logics wrote: | cause the button clicking Bill Gates Labradors want click able buttons and all should be in C. |
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 " 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 ad libitum.
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 |
|
|
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Fri Apr 05, 2013 1:53 pm Post subject: |
|
|
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. _________________ My blog |
|
Back to top |
|
|
yngwin Retired Dev
Joined: 19 Dec 2002 Posts: 4572 Location: Suzhou, China
|
Posted: Fri Apr 05, 2013 3:48 pm Post subject: |
|
|
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 |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10587 Location: Somewhere over Atlanta, Georgia
|
Posted: Tue Apr 09, 2013 8:59 pm Post subject: |
|
|
For use with C?
- John _________________ I can confirm that I have received between 0 and 499 National Security Letters. |
|
Back to top |
|
|
ulenrich Veteran
Joined: 10 Oct 2010 Posts: 1480
|
Posted: Tue Apr 09, 2013 9:48 pm Post subject: |
|
|
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. | |
This way using a compiler no c code will be left, only machine code will interact! |
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10587 Location: Somewhere over Atlanta, Georgia
|
Posted: Tue Apr 09, 2013 10:27 pm Post subject: |
|
|
As opposed to the normal way you use C and C++ without a compiler?
- John _________________ I can confirm that I have received between 0 and 499 National Security Letters. |
|
Back to top |
|
|
ulenrich Veteran
Joined: 10 Oct 2010 Posts: 1480
|
Posted: Tue Apr 09, 2013 10:55 pm Post subject: Re: QT without c++? |
|
|
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? |
|
Back to top |
|
|
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Sat Apr 13, 2013 4:18 pm Post subject: Re: QT without c++? |
|
|
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. _________________ My blog |
|
Back to top |
|
|
wolfieh n00b
Joined: 17 Nov 2009 Posts: 54
|
Posted: Sat Apr 13, 2013 5:41 pm Post subject: |
|
|
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 |
|
|
i92guboj Bodhisattva
Joined: 30 Nov 2004 Posts: 10315 Location: Córdoba (Spain)
|
Posted: Sat Apr 13, 2013 6:11 pm Post subject: |
|
|
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
There are bindings for many languages, though, for those that are picky about having to write a couple of keywords here and there
http://qt-project.org/wiki/Category:LanguageBindings |
|
Back to top |
|
|
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Mon Apr 15, 2013 7:13 pm Post subject: |
|
|
^^
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... _________________ My blog |
|
Back to top |
|
|
i92guboj Bodhisattva
Joined: 30 Nov 2004 Posts: 10315 Location: Córdoba (Spain)
|
Posted: Mon Apr 15, 2013 7:37 pm Post subject: |
|
|
No, I mean what I wrote
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. |
|
Back to top |
|
|
lost+found Guru
Joined: 15 Nov 2004 Posts: 509 Location: North~Sea~Coa~s~~t~~~
|
Posted: Tue Apr 16, 2013 7:28 am Post subject: |
|
|
GNUstep has a fast gui designer. C is a subset of Objective-C. |
|
Back to top |
|
|
dE_logics Advocate
Joined: 02 Jan 2009 Posts: 2253 Location: $TERM
|
Posted: Fri Apr 19, 2013 5:25 pm Post subject: |
|
|
i92guboj wrote: | No, I mean what I wrote
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. _________________ My blog |
|
Back to top |
|
|
|