my own c++ qt library to be used in qtruby, qtpython etc - c++

I'm starting an institute project. I'll try to create a "web-typograph", a tool that's to be used to correct texts (according to typographic rules of a language) before they're sent to the site. My choice is C++ with Qt because I'd like to create "multilingual" library (I mean it could be used from Ruby, Python, PHP and so on).
Honestly, I heard something about QtRuby, QtPython (even PHP Qt...) but I just can't imagine, how I can bind my library with them.
P.S. Yes, I've googled. But some comments of the experienced would be nice :)

PyQt and the other bindings to Qt are bindings to the core Qt library. To add bindings to your own (possibly Qt-based) classes, you'll have to use tools like SWIG or SIP (PyQt's tool which may be more relevant for Qt-related classes) to generate the bindings. Alternatively, you can make a C API to your library which is easier to wrap and bind from scripting languages.
That said, you should first understand what you need Qt for at all. Are you planning a GUI or using any other capabilities Qt provides? Which?

Related

How to use multiple programming languages in one GTK application?

I am currently learning GTK, specifically gtkmm. As i can see GTK has excellent support in different languages through bindings. So one can use c, c++, js, python and more to implement gtk apps. Thats great. But what if i wanted to create one application, say the base window and some api objects/instances in gtkmm and c++ and want to let others create modules in any other language that has gtk binding. I want to share the api objects/instances (say they are singletons) between all modules. But i definitely don't want to spawn multiple processes for this to work. I know boost has support for exposing c++ objects into python modules. I am looking for something like that. But from the documentation so far (i haven't finished it yet, so forgive me if i have missed anything), i couldn't find the proper way to do that.

GUI developement using Python and tkinter vs Qt and C++

I am trying to make a decision for what to use to continue developing my application.
I have some experience with C++ in the MFC Document/View architecture and have found it very frustrating. I felt I was always fighting the framework and also felt that my application didn't fit the doc/view architecture. (I now know that it probably would have fit, if I had known how to structure it that way.)
So I decided to try Python and ended up using tkinter. That was easier to learn and didn't have as many frustrations. (Though it had a few different new ones.) I think I learned a bit more about object orientation and setting up classes along the way. But am now concerned about the fact that it is an interpreted language and much slower than C++ for my purpose.
So I have been wanting to go back to C++ but not MFC. I have read a little about wxWidgets and Qt.
So here are the things I want to know:
For wxWidgets and Qt, do they use a resource editor for setting up the layout of a GUI or directly expose the code the way Python and tkinter do.
Do either wxWidgets or Qt produce any interpreted code or is everything ultimately compiled into native machine code?
Thanks
1. Both
Qt and wxWidgets have GUI builders available. In the case of Qt, an XML file is produced that is parsed by the uic to produce C++ code. wxWidgets has several designers available, they will differ between them, but I'll be surprised if they don't all follow the same pattern.
However many people, myself included, choose to hand code - there is no requirement to use the UI designers. Be careful using the term 'resource editor', as Qt has a Resource Editor and it is not used for designing GUIs.
2. Both
Qt and wxWidgets are not just GUI frameworks - they're cross-platform toolkits. In view of this, Qt is pushing for a clear separation between GUI and backend by using QtQuick and the QML language for GUI development. Qt5 still has full support for C++ widget-based development of course. wxWidgets has no equivalent that I'm aware of.
Also, if you liked Python but not tkinter, both Qt and wxWidgets have Python bindings.

Prototyping Qt/C++ in Python

I want to write a C++ application with Qt, but build a prototype first using Python and then gradually replace the Python code with C++.
Is this the right approach, and what tools (bindings, binding generators, IDE) should I use?
Ideally, everything should be available in the Ubuntu repositories so I wouldn't have to worry about incompatible or old versions and have everything set up with a simple aptitude install.
Is there any comprehensive documentation about this process or do I have to learn every single component, and if yes, which ones?
Right now I have multiple choices to make:
Qt Creator, because of the nice auto completion and Qt integration.
Eclipse, as it offers support for both C++ and Python.
Eric (haven't used it yet)
Vim
PySide as it's working with CMake and Boost.Python, so theoretically it will make replacing python code easier.
PyQt as it's more widely used (more support) and is available as a Debian package.
Edit: As I will have to deploy the program to various computers, the C++-solution would require 1-5 files (the program and some library files if I'm linking it statically), using Python I'd have to build PyQt/PySide/SIP/whatever on every platform and explain how to install Python and everything else.
I want to write a C++ application with Qt, but build a prototype first using Python and then gradually replace the Python code with C++. Is this the right approach?
That depends on your goals. Having done both, I'd recommend you stay with Python wherever possible and reasonable. Although it takes a bit of discipline, it's very possible to write extremely large applications in Python. But, as you find hotspots and things that can be better handled in C++, you can certainly port relevant parts to C++.
Is there any comprehensive documentation about this process or do I have to learn every single component, and if yes, which ones?
Here's what I'd recommend for the various pieces:
EDITOR/IDE: Use any editor/IDE you're comfortable with, but I'd highly recommend one that supports refactoring. If you're comfortable with Eclipse, use it. If you want to mainly go the C++ route and you're not too familiar with any editors, you might be better off with QtCreator. Eric is an extremely good Python IDE with support for refactoring, unless you're going to be doing lots of C++, take a look at it. Even better, its source code is an example of good PyQt usage and practices.
PROCESS:
The quick summary:
Write your application in Python using PyQt
When identified as hotspots, convert decoupled Python classes to C++
Create bindings for those classes using SIP
Import the newly defined libraries in Python in place of their Python counterparts
Enjoy the speed boost
General details:
Write the application in Python using PyQt. Be careful to keep a good separation of concerns so that when you need to port pieces to C++ they will be separate from their dependencies. When you finally need to port something to C++, write it in C++/Qt and then create bindings for it using SIP. SIP has a good reference manual on the process, and you have all of PyQt as an example.
DEPLOYMENT:
C++ - For many applications the dependencies are sufficiently simple that it's not too difficult to create an installer using a tool like NullSoft's Installer or InnoSetup.
Python/PyQt - PyQt applications are a bit more difficult to install because of the dependency on Python and its dependence on the presence of the Qt libraries. One person documented his efforts on this post at ARSTechnica. py2exe works pretty well on Windows and should work fine. IME, freeze.py, which comes with the Python source, sometimes has problems determining which shared libraries are truly necessary and will sometimes end up creating a binary whose dependencies aren't present. Py2app can be made to work on Mac OS X.
But worse, however, is the PyQt/Qt licensing. If you are developing a commercial application, you need to have a commercial PyQt (and Qt) license and make sure to prevent the users from easily modifying the source or otherwise writing code against the PyQt/Qt API because of licensing restrictions. Because of that, the PyQt author created a tool called VendorId (although it has a Python license). Within VendorId is a tool called SIB that can be used to create an executable which depends only on the Python interpreter. But, if you're going to go this far, you might want to install a custom Python along with your application.
DISCLAIMER: I haven't used PySide at all, so I'm not sure how it compares to PyQt. Also, note the following warning on their website:
PySide is a work in progress and is not yet suited for application development requiring production-level stability.
But, on a good note, they intend, at least for the initial release to "maintain API compatibility with PyQt." So, aside from the C++ bindings, you could easily switch between the two later.
If you are just learning Qt and want to leverage the speed of prototyping that Python gives you, then I would recommend you make a sample project using PyQt. As you said, there is a debian package, so you are just a simple apt-get away from making your first application.
I personally use gVim as my Python/Qt editor, but you can really use any Python-friendly editor without much trouble. I liked WingIDE and they have auto-complete for Qt but once you sip from the vim kool-aid it's hard to switch.
I would say that PySide is 95%+ compatible with PyQt and the LPGL license is nice, but if you are just trying to prototype your first Qt app, then I don't think there is a real reason to use PySide. Although, I do like the PySide docs better, you can also just use them and replace all the library references with PyQt.
Depending on the complexity of the application you are building, it might be better off to just start from scratch with a C++ version than to try to do a bunch SIP refactoring black magic. Once you have a solid grasp of the Qt framework, you should be able to switch between the C++ and Python bindings pretty effortlessly.
I would draw UI mockups before starting to code prototypes. Here are some benefits:
Quicker than coding prototypes as there is no programming involved
Quickly fill widgets, such as tables and trees, with data
Add descriptions and notes to your screens
Easily integrate mockups into specification documents without having to capture screens
Validate UI design concepts before implementing
There are a lot of tools that can help you do that, but if you are going to use Qt, MockupUI may be a good choice as it renders Qt widgets with native styles for Windows 7,8 or 10 which makes your mockup look more realistic.

C++ HTML generation classes

A question prompted by jbar's question.
In scripting languages like Python, Ruby, and Perl, there are libraries that simplify generating dynamic HTML. (For example, the cgi module in Ruby.)
Are there any similar packages for C++? I don't know of one, and at least some desultory googling didn't reveal one.
http://www.webtoolkit.eu/wt#/
I don't know anything about it, but their web-page is clean and the introduction sounds like exactly what you're looking for...
Wt (pronounced 'witty') is a C++ library and application server for developing and deploying web applications. It is not a 'framework', which enforces a way of programming, but a library.
...
In contrast, a web application developed with Wt is written in only one compiled language (C++), from which the library generates the necessary HTML/XHTML, Javascript, CGI, SVG/VML/Canvas and AJAX code.
Cgicc does HTML generation. I've toyed with it once, and it seemed pretty nice.

What embedded browser for C++ project?

Is there any browser I could embedd in C++ application on Windows?
I need all features typical browser has (HTTP client, cookies support, DOM style HTML parser, JavaScript engine) except rendering.
Because I don't need rendering capability (and that's rather big part of a browser) I would prefer a browser with non monolithic design so I wouldn't have to include rendering stuff into my project.
It would be nice if it had C++ rather than C API.
I need this embedded browser mainly because I have much trouble finding C++ HTML parser which could handle broken HTML like browsers do.
If you know any, please answer Library Recommendation: C++ HTML Parser SO question or at least vote on it to increase a chance someone will give a good answer.
Sounds like all you need is something like libcurl which is an HTTP library and will let you do GET/POST/etc.
When I think browser I generally think rendering/JavaScript and not HTTP library.
Edit
In that case I'd look at WebKit (which I think has a C++ API) and hope you don't have to pull too much in.
Edit Again
On second thought (since rendering is such a big part of what browsers do), you might be better off using a stand-alone JS engine like SpiderMonkey and a stand-alone XML parser like Xerces-C (plus maybe tidy to make your HTML into XML).
I'm a bit confused by your question regarding embedding a web browser for which you don't need rendering capabilities. A web browser is rendering web pages by definition, unless you just need HTTP and XML with JavaScript capabilities which is a subset of a browser functionalities?
If you need a web browser to embed in your C++ application, I would suggest to consider Qt that comes with the WebKit plugin. It is C++, LGPL and has a very nice IDE (Qt Creator). I tried Qt with Qt Creator on unix (Ubuntu) and it was very impressive. The debugger is a bit light but it is just the first version. The adapter of Qt into visual c++ 2008 is now free.
You might also want to check out Awesomium-- it's free for non-commercial use and has all of the features you're looking for (if you don't need rendering, simply don't use it).
There is a project called CEF = The Chromium Embedded Framework - it is:
a simple framework for
embedding Chromium-based browsers in other applications. It is a
BSD-licensed open source project founded by Marshall Greenblatt in
2008 and based on the Google Chromium project. Unlike the Chromium
project itself, which focuses mainly on Google Chrome application
development, CEF focuses on facilitating embedded browser use cases in
third-party applications.
and yes:
The base CEF framework includes support for the C and C++ programming
languages.
Including javascript support and html parsing makes this non-trivial task - you have to use one of the available browsers.
IE is usable through its COM model - you can create instance of it in your window be it invisible or not and call its javascript/html capabilities.
It has been designed to be used like that since the beginning and certainly it is working fine.
The other options are:
Gecko/Mozilla - a couple of years ago it wasn't usable like this, currently I think it is.
WebKit/V8 - no public API has been released for chrome yet, you could use webkit itself, but it doesn't have javascript engine. Another option is to take a look at the Chrome codebase and see if you could get out of it what you need.
I would probably go for IE, since it is maybe the easiest option and I have already used it. The other options seem to me more like building a browser instead of just using it.
How about Gecko ? You may not need the entire engine but you may find some its components useful like SpiderMonkey which is a JavaScript engine written in C.
I'd recommend picking up Qt for C++ programming. It has a built-in library that embeds Webkit with all the bells'n'whistles, and Qt is a great C++ library in general.
Old question, I know, but take a look on
http://msdn.microsoft.com/en-us/library/ky29ffxd%28v=vs.94%29.aspx
IActiveScript and family COM interfaces allows script execution (not only JS, any language that registers as script interpeter, for that matter) in-memory.