Hello,
thanks for your reply!
Of course I am using signals and stuff, I just left out the least important bits of information. Of course the interface function is a signal too, I just left it out because I didn't want to spam this topic.
If you say you don't understand what I am doing let me explain it to you quickly:
As said before, I have implemented a "find text" dialog, which allows you to search for text in a QTextEdit.
The first class (findTextDialog) handles the gui stuff of the dialog. The function/slot I have pasted is the slot which gets executed when the user presses the "&Find" button.
The function onFindButtonSlot then emits a signal on an interface.
The interface is a common place where signals for view<->controller interactions are saved. This might seem a little odd at first glance, but it is called a hexagonal MVC pattern, there is no direct contact between view and controller clases at all.
The controller class findReplaceController connects to the specific interface signals when the application starts. It also receives the "find text" signal emitted from the find text dialog.
As parameter some eventargs are passed. This structure saves information about what to search as well as some search options. It is this variable which gets corrupted during transfer over the signals. Like I mentioned before, this is odd because it used to work yesterday (c).
I hope with these explanations and with the new code my problem makes more sense to you than it does to me now 
Ok, let's start with a more verbose code dump :
FindTextDialog - The one who emits the signal..
class findTextDialog
: public QDialog{
Q_OBJECT
//
void onFindButtonSlot ()
{
LOG_DEBUG("findTextDialog::onFindButtonSlot");
// setup find text event args from dialog
interfaces::eventArgs::findTextEventArg args;
args._findString = ui.findStringTextbox->text();
args._caseSensitive = (ui.matchCaseCheckBox->checkState() == Qt::Checked);
args._wholeWord = (ui.wholeWordCheckbox->checkState() == Qt::Checked);
args._backwards = (ui.findBackwardsCheckbox->checkState() == Qt::Checked);
LOG_ERROR
(QString("VIEWFIND: %1").
arg(ui.
findStringTextbox->text
()).
toStdString());
// trigger event in interface
emit getFindTextInterface().onFindTextSignal (&args);
// close dialog
onCancelButtonSlot ();
}
};
class findTextDialog : public QDialog
{
Q_OBJECT
//
void onFindButtonSlot ()
{
LOG_DEBUG("findTextDialog::onFindButtonSlot");
// setup find text event args from dialog
interfaces::eventArgs::findTextEventArg args;
args._findString = ui.findStringTextbox->text();
args._caseSensitive = (ui.matchCaseCheckBox->checkState() == Qt::Checked);
args._wholeWord = (ui.wholeWordCheckbox->checkState() == Qt::Checked);
args._backwards = (ui.findBackwardsCheckbox->checkState() == Qt::Checked);
LOG_ERROR (QString("VIEWFIND: %1").arg(ui.findStringTextbox->text()).toStdString());
// trigger event in interface
emit getFindTextInterface().onFindTextSignal (&args);
// close dialog
onCancelButtonSlot ();
}
};
To copy to clipboard, switch view to plain text mode
The interface - This class stores some signals which controller and view use to communicate
class findTextInterface
: public QObject,
public genericInterface
{
Q_OBJECT
signals:
//! Signals sent FROM the view TO the controller
/// Start searching for some text.. sent by the find button of the find text dialog
void onFindTextSignal (interfaces::eventArgs::findTextEventArg* searchParameter);
};
class findTextInterface : public QObject, public genericInterface
{
Q_OBJECT
signals:
//! Signals sent FROM the view TO the controller
/// Start searching for some text.. sent by the find button of the find text dialog
void onFindTextSignal (interfaces::eventArgs::findTextEventArg* searchParameter);
};
To copy to clipboard, switch view to plain text mode
FindReplaceController - This is the class which should take care of doing the "find text" logic
/**
@brief Controller class to select(find) and replace text
*/
class findReplaceController
: public QObject,
public genericController
{
Q_OBJECT
virtual void connectSignals ()
{
// find text
connect (getFindTextInterface(),
SIGNAL(onFindTextSignal(interfaces::eventArgs::findTextEventArg*) ),
this, SLOT(findTextSlot(interfaces::eventArgs::findTextEventArg*)));
}
public slots:
/**
@brief Called from the view, this finds some text in the front file in the editor
*/
void findTextSlot interfaces::eventArgs::findTextEventArg* arg)
{
// This crashes sometimes or gives bad data
LOG_ERROR
(QString("SEARCHSTRING: %1").
arg(arg
->_findString
).
toStdString());
}
};
/**
@brief Controller class to select(find) and replace text
*/
class findReplaceController : public QObject, public genericController
{
Q_OBJECT
virtual void connectSignals ()
{
// find text
connect (getFindTextInterface(),
SIGNAL(onFindTextSignal(interfaces::eventArgs::findTextEventArg*) ),
this, SLOT(findTextSlot(interfaces::eventArgs::findTextEventArg*)));
}
public slots:
/**
@brief Called from the view, this finds some text in the front file in the editor
*/
void findTextSlot interfaces::eventArgs::findTextEventArg* arg)
{
// This crashes sometimes or gives bad data
LOG_ERROR (QString("SEARCHSTRING: %1").arg(arg->_findString).toStdString());
}
};
To copy to clipboard, switch view to plain text mode
FindTextEventArgs - This is passed over the interface from the view
struct findTextEventArg
{
//! Search parameters
bool _caseSensitive;
bool _backwards;
bool _wholeWord;
};
struct findTextEventArg
{
//! Search parameters
QString _findString;
bool _caseSensitive;
bool _backwards;
bool _wholeWord;
};
To copy to clipboard, switch view to plain text mode
Thanks for help and replies,
Bye, Headhunter
(Hope the forum doesn't kill my beautiful code intendention)
Bookmarks