Make Qt5 connect style work in Qt4 - c++

I want to port an app (small to mid size) from Qt5 to Qt4. Do I need to manually rewrite all the connects (which currently use the new Qt5 style)?
I'm looking for an alternative (easy) approach :)

Another approach is to instrument connect to dump the old-style syntax equivalent at runtime, with file name and line number, and use that to replace the new-style connects with old-style connects.
By instrumenting connect I mean replacing the connect with myConnect macro using search-and-replace, and writing your own myConnectImpl that executes QObject::connect and then synthesizes the old-style connect and dumps it. To convert method pointers to method indexes, use mataobject->static_metacall(object, QMetaObject::IndexOfMethod, args) for the metaobject of a given class and then proceed up the superclasses till you reach QObject.
You do have to understand some implementation details to pull that off. Perhaps this answer-in-progress will provide some inspiration.

AFAIK, yes. But you can always make a little script to go fileby file and change them.

Related

Interactive Command Line Interface for Qt

I'm looking to create a cross-platform readline/linenoise type command line interface for an application in Qt. I'd rather not reinvent the wheel if possible. The terminal in which the user is operating should be able to receive commands via a command prompt. This will be done in Qt, thus my question is: is there a Qt-esque way of doing this via signals and slots such that when a user enters a line into the terminal a slot can be called?
I understand that this can be fairly simply done using a QThread and running a blocking process to signal on a line being read. This question is specifically geared towards using built-in Qt functionality.
While attempting to discern a viable answer to this, I realized that my question was improperly phrased. I was looking for what could be termed a Terminal Emulator. There are several existing solutions to this, including QTermWidget. However, it appears that there does not yet exist a non-UI based terminal emulator for Qt. That is, in order to use these one must have an active UI instance of Qt, not merely employing a Qt Command Line application.
Going the route of using a simple Qt Command Line, it is not as simple as connecting something like a QTextStream and observing the output of the command line. As with most command line programs, native, low-level processing must occur in order to assess things like the arrow keys. Unfortunately QKeyPressEvent and the like require the UI to be running.

Eiffel: EWF_APP_EXECUTION (EWF application) exit function

As there is an initialize function, is there an exit/on_exit function such as I can close my database connection into it?
I would suggest to handle this at the request level to be fully portable among various EiffelWeb connectors.
Now, could you tell us which solution you are using ? EiffelWeb standalone connector, or rather libfcgi with apache for instance? or else?
For standalone, you can redefine the "launch" procedure, in order to perform cleanup task when you exit the application (which is also the server).
For libfcgi, the C API may provide such facility, but so far, the Eiffel libfcgi library does not wrap it. If needed this may be possible to implement it.
Called in each request which is probably not the best solution but I have chosen following way for the moment:
Redefine the clean procedure of WSF_FILTERED_ROUTED_EXECUTION inherited into the classical EWF_APP_EXECUTION to close the connection
Connect into the redefined initialize

Where to declare object returned from Qt SIGNAL/SLOT?

I've got a FTP application written in c++. Now I'm adding a simple GUI to my project via the Qt plugin for VS2010. The mechanism to connect to the server is very simple. After typing both IP and PORT the connection is stablished and an object is created. This object (from a class I've written) can call several functions such as: ask for the available files on server, download an specific file, etc.
My question is: if that object is created after pressing a button (and calling the function it is linked to) is there any way to return that object? Sure there is but, how and where in the code should it be stored/declared. Here is the code line:
connect(ui.btn_connect,SIGNAL(clicked()),this,SLOT(on_SayConnect()));
How should I call the function "on_SayConnect()" if I want an object to be returned using the connect (SIGNAL/SLOT) syntax? Thank you in advance.
There's no good way to return values using the connect method. If your goal is to have the this object (I don't think you actually gave it a name) send a value/object to other parts of the system, you could have the on_SayConnect slot emit a signal with the desired value. Any other objects that need to receive that value should implement and connect the proper slot to do so.

C++, linux: how to limit function access to file system?

Our app is ran from SU or normal user. We have a library we have connected to our project. In that library there is a function we want to call. We have a folder called notRestricted in the directory where we run application from. We have created a new thread. We want to limit access of the thread to file system. What we want to do is simple - call that function but limit its access to write only to that folder (we prefer to let it read from anywhere app can read from).
Update:
So I see that there is no way to disable only one thread from all FS but one folder...
I read your propositions dear SO users and posted some kind of analog to this question here so in there thay gave us a link to sandbox with not a bad api, but I do not really know if it would work on anething but GentOS (but any way such script looks quite intresting in case of using Boost.Process command line to run it and than run desired ex-thread (which migrated to seprate application=)).
There isn't really any way you can prevent a single thread, because its in the same process space as you are, except for hacking methods like function hooking to detect any kind of file system access.
Perhaps you might like to rethink how you're implementing your application - having native untrusted code run as su isn't exactly a good idea. Perhaps use another process and communicate via. RPC, or use a interpreted language that you can check against at run time.
In my opinion, the best strategy would be:
Don't run this code in a different thread, but run it in a different process.
When you create this process (after the fork but before any call to execve), use chroot to change the root of the filesystem.
This will give you some good isolation... However doing so will make your code require root... Don't run the child process as root since root can trivially work around this.
Inject a replacement for open(2) that checks the arguments and returns -EACCES as appropriate.
This doesn't sound like the right thing to do. If you think about it, what you are trying to prevent is a problem well known to the computer games industry. The most common approach to deal with this problem is simply encoding or encrypting the data you don't want others to have access to, in such a way that only you know how to read/understand it.

Qt, Signals without naming?

Is there any way to use the signals without MOC and without the connecting via names? My one problem with Qt is that you have something like
this->connect(this->SaveBtn, SIGNAL(click()), SLOT(SaveClicked()));
And there is no error detection to tell that is wrong other then finding out the button doesn't work or searching through their documentation to find out the signal doesn't exist. Also it seems pointless and a waste of cycles to connect via names instead of classes.
There is error detection, the connect function returns false when it fails to connect, and a warning is output on standard error (or, on Windows, to the weird place which DebugView reads from). Also you can make these warnings into fatal errors by setting QT_FATAL_WARNINGS=1 in your environment.
It's not pointless to connect by name. For example, it means that connections can be established where the signal/slot names are generated at runtime.
Other than the fact that signals are just methods, no I don't think you can use them like they are intended without the intermediate MOC step. It is a pain when you mess up the connection and there is no flag raised. What does your last sentence mean? Can you elaborate what your problem is? Signals/Slots is not a perfect system, I don't think a perfect system exits, but it is pretty intuitive and has worked well for me.
No, there is no real way around that.
You'll have to use MOC and connect via names. But with time you'll find out that it "grows on you" and won't really bother you. Train yourself to add code in small snippets each time, testing that what you added works, and you'll have no trouble with this.
I normally Practice following style of coding,
m_pCancelPushButton = new QPushButton(tr("Cancel"));
m_pCancelPushButton->setObjectName("CancelButton");
//MetaObject Connections
QMetaObject::connectSlotsByName (this);
This enable me to write code
void Class_name::on_CancelButton_clicked()
{
//Do your job here.
reject();
}
I hope it will help you.
Thanks,
Rahul