Hello!
I write GUI and try to send signal with vector.
There is small example (https://root.cern.ch/root/htmldoc/guides/users-guide/WritingGUI.html#a-simple-example, 27.7 Event Processing: Signals and Slots) how to send Int_t type.
//root cern threads
#include "TThread.h"
#include <Riostream.h>
//root cern general
#include <TApplication.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TRandom.h>
//root cern GUI
#include <TGClient.h>
#include <TGButton.h>
#include <TRootEmbeddedCanvas.h>
#include "TGFrame.h"
#include "TGTab.h"
#include <TQObject.h>
#include <RQ_OBJECT.h>
using namespace std;
class MyClass
{
RQ_OBJECT("MyClass")
private:
Int_t fValue;
public:
MyClass() { fValue=0; }
Int_t GetValue() const { return fValue; }
void SetValue(Int_t); // *SIGNAL*
};
void MyClass::SetValue(Int_t v)
{
if (v != fValue)
{
fValue = v;
Emit("SetValue(Int_t)",v);
}
}
void siglan_slot_int()
{
MyClass *objA = new MyClass();
MyClass *objB = new MyClass();
objA->Connect("SetValue(Int_t)","MyClass",objB,"SetValue(Int_t)");
//objB->SetValue(11);
objA->SetValue(79);
cout << "objA->GetValue()" << objA->GetValue() << endl;
cout << "objB->GetValue()" << objB->GetValue() << endl;
}
This code works for Int_t .
I need the same for vector, for example.
//root cern threads
#include "TThread.h"
#include <Riostream.h>
//root cern general
#include <TApplication.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TRandom.h>
//root cern GUI
#include <TGClient.h>
#include <TGButton.h>
#include <TRootEmbeddedCanvas.h>
#include "TGFrame.h"
#include "TGTab.h"
#include <TQObject.h>
#include <RQ_OBJECT.h>
//using namespace std;
class MyClass
{
RQ_OBJECT("MyClass")
private:
std::vector<Int_t> fValue_vec;
public:
MyClass() { fValue_vec.resize(5); }
Int_t GetValue() const { return fValue_vec; }
void SetValue(std::vector<Int_t>); // *SIGNAL*
};
void MyClass::SetValue(std::vector<Int_t> v)
{
for (int i = 0; i < fValue_vec.size(); ++i)
{
fValue_vec[i] = v[i];
}
Emit("SetValue(std::vector<Int_t>)",v);
}
void signal_slot_vector()
{
MyClass *objA = new MyClass();
MyClass *objB = new MyClass();
objA->Connect("SetValue(std::vector<Int_t>)","MyClass",objB,"SetValue(std::vector<Int_t>)");
std::vector<Int_t> vec_a;
vec_a.push_back(1);
vec_a.push_back(2);
vec_a.push_back(3);
vec_a.push_back(4);
vec_a.push_back(5);
objA->SetValue(vec_a);
}
Output of this code:
Error: Function vector<Int_t>)",v) is not defined in $Emit("SetValue(std signal_slot_vector.cpp:41:
*** Interpreter error recovered ***
Another variant without std does not work too:
//root cern threads
#include "TThread.h"
#include <Riostream.h>
//root cern general
#include <TApplication.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TRandom.h>
//root cern GUI
#include <TGClient.h>
#include <TGButton.h>
#include <TRootEmbeddedCanvas.h>
#include "TGFrame.h"
#include "TGTab.h"
#include <TQObject.h>
#include <RQ_OBJECT.h>
using namespace std;
class MyClass
{
RQ_OBJECT("MyClass")
private:
vector<Int_t> fValue_vec;
public:
MyClass() { fValue_vec.resize(5); }
Int_t GetValue() const { return fValue_vec; }
void SetValue(vector<Int_t>); // *SIGNAL*
};
void MyClass::SetValue(vector<Int_t> v)
{
for (int i = 0; i < fValue_vec.size(); ++i)
{
fValue_vec[i] = v[i];
}
Emit("SetValue(vector<Int_t>)",v);
}
void signal_slot_vector_no_std()
{
MyClass *objA = new MyClass();
MyClass *objB = new MyClass();
objA->Connect("SetValue(vector<Int_t>)","MyClass",objB,"SetValue(vector<Int_t>)");
vector<Int_t> vec_a;
vec_a.push_back(1);
vec_a.push_back(2);
vec_a.push_back(3);
vec_a.push_back(4);
vec_a.push_back(5);
objA->SetValue(vec_a);
}
Output:
Error: Function Emit("SetValue(vector<Int_t>)",v) is not defined in current scope signal_slot_vector_no_std.cpp:41:
*** Interpreter error recovered ***
P.S. my root is
ROOT 5.34/36 (v5-34-36@v5-34-36, Apr 05 2016, 10:25:45 on linuxx8664gcc)
CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
My system is
Scientific Linux release 7.3 (Nitrogen)
Thank you in advance.