Qt: исключения в слотах
Столкнулся с такой проблемой - если слот вызывается сигналом, а не как обычная функция, то при генерации в нём exception'а программа аварийно завершается. try - catch её не обрабатывает!
Я так понимаю, дело в реализации соединений сигналов со слотами...
Подскажите, возможно ли эти исключения всё-таки как-нибудь обрабатывать.
Ставь обработчик на сигнал.
Я же написал - обработчик не помогает. Он правда стоит не на самом сигнале, а на функции, которая этот сигнал "подаёт". Но ведь exception должен следовать вверх по цепочке вызовов, пока не встретит обработчик... или я что-то не правильно понимаю?
Объянсни что значит слот вызывается сигналом. А лучше код.... в студию!
Простите за вопрос, но Вы когда-нибудь использовали библиотеку Qt?
Да. использовал. Но к теме это не имеет никакого отношения =)
дело в том что понятие сигнал, здесь может иметь двоякое понимание
Цитата:
Signals
Signals are emitted by an object when its internal state has changed in some way that might be interesting to the object's client or owner. Only the class that defines a signal and its subclasses can emit the signal.
When a signal is emitted, the slots connected to it are usually executed immediately, just like a normal function call. When this happens, the signals and slots mechanism is totally independent of any GUI event loop. Execution of the code following the emit statement will occur once all slots have returned. The situation is slightly different when using queued connections; in such a case, the code following the emit keyword will continue immediately, and the slots will be executed later.
If several slots are connected to one signal, the slots will be executed one after the other, in an arbitrary order, when the signal is emitted.
Signals are automatically generated by the moc and must not be implemented in the .cpp file. They can never have return types (i.e. use void).
A note about arguments: Our experience shows that signals and slots are more reusable if they do not use special types. If QScrollBar::valueChanged() were to use a special type such as the hypothetical QScrollBar::Range, it could only be connected to slots designed specifically for QScrollBar. Something as simple as the program in Tutorial 5 would be impossible.
Slots
A slot is called when a signal connected to it is emitted. Slots are normal C++ functions and can be called normally; their only special feature is that signals can be connected to them.
Since slots are normal member functions, they follow the normal C++ rules when called directly. However, as slots, they can be invoked by any component, regardless of its access level, via a signal-slot connection. This means that a signal emitted from an instance of an arbitrary class can cause a private slot to be invoked in an instance of an unrelated class.
You can also define slots to be virtual, which we have found quite useful in practice.
Compared to callbacks, signals and slots are slightly slower because of the increased flexibility they provide, although the difference for real applications is insignificant. In general, emitting a signal that is connected to some slots, is approximately ten times slower than calling the receivers directly, with non-virtual function calls. This is the overhead required to locate the connection object, to safely iterate over all connections (i.e. checking that subsequent receivers have not been destroyed during the emission), and to marshall any parameters in a generic fashion. While ten non-virtual function calls may sound like a lot, it's much less overhead than any new or delete operation, for example. As soon as you perform a string, vector or list operation that behind the scene requires new or delete, the signals and slots overhead is only responsible for a very small proportion of the complete function call costs.
The same is true whenever you do a system call in a slot; or indirectly call more than ten functions. On an i586-500, you can emit around 2,000,000 signals per second connected to one receiver, or around 1,200,000 per second connected to two receivers. The simplicity and flexibility of the signals and slots mechanism is well worth the overhead, which your users won't even notice.
Note that other libraries that define variables called signals or slots may cause compiler warnings and errors when compiled alongside a Qt-based application. To solve this problem, #undef the offending preprocessor symbol.
Ладно.. я готов призать свои ошибки. Хорошо, просто покажи кусок кода сигнала (как оне у тебя испускается) и слота (вмсете с try`ем и excption`om)
Сигналы Qt к сигналам ядра никакого отношения не имеют. К тому же - это кроссплатформенная библиотека; может использоваться на *nix системах (включая MacOS X), Windows и т.д.