Hi,
I am using VS 2019 with ROOT 6.18 to generate a GUI that should plot a sinx/x graph when the Draw button is clicked and close when the Exit button is clicked however I am having issues. This is an example found in p. 570 of the ROOT guide. I have looked at other posts that have similar problems and a solution that worked but I haven’t been able to understand it. I believe the solution involves dictionaries (which I am unfamiliar with).
In myFrame.h, when the line ClassDef(MyMainFrame, 0) is commented out, the GUI opens and the Exit button works but when it is included, I get the following errors:
-
myFrame.obj : error LNK2019: unresolved external symbol “public: static class TClass * __cdecl MyMainFrame::Class(void)” (?Class@MyMainFrame@@SAPAVTClass@@XZ) referenced in function "public: virtual class TClass * __thiscall MyMainFrame::IsA(void)const " (?IsA@MyMainFrame@@UBEPAVTClass@@XZ)
-
myFrame.obj : error LNK2019: unresolved external symbol “public: virtual void __thiscall MyMainFrame::Streamer(class TBuffer &)” (?Streamer@MyMainFrame@@UAEXAAVTBuffer@@@Z) referenced in function “[thunk]:public: virtual void __thiscall MyMainFrame::Streamer`adjustor{48}’ (class TBuffer &)” (?Streamer@MyMainFrame@@WDA@AEXAAVTBuffer@@@Z)
ex2aLinkDef.h
#pragma link C++ class MyMainFrame;
myFrame.h
#include <TQObject.h>
#include <TApplication.h>
#include <TGClient.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TRandom3.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TRootEmbeddedCanvas.h>
#include <RQ_OBJECT.h>
#include "ex2aLinkDef.h"
class MyMainFrame : public TGMainFrame {
private:
TRootEmbeddedCanvas* fEcanvas;
public:
MyMainFrame(const TGWindow* p, UInt_t w, UInt_t h);
virtual ~MyMainFrame();
void DoDraw();
void doClose(void);
//ClassDef(MyMainFrame, 0)
};
myFrame.cpp
#include "myFrame.h"
#include "ex2aLinkDef.h"
MyMainFrame::MyMainFrame(const TGWindow* p, UInt_t w, UInt_t h)
: TGMainFrame(p, w, h) {
// Creates widgets of the example
fEcanvas = new TRootEmbeddedCanvas("Ecanvas", this, 200, 200);
AddFrame(fEcanvas, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
10, 10, 10, 1));
TGHorizontalFrame* hframe = new TGHorizontalFrame(this, 200, 40);
TGTextButton* draw = new TGTextButton(hframe, "&Draw");
draw->Connect("Clicked()", "MyMainFrame", this, "DoDraw()");
hframe->AddFrame(draw, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
TGTextButton* exit = new TGTextButton(hframe, "&Exit ",
"gApplication->Terminate()");
hframe->AddFrame(exit, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
AddFrame(hframe, new TGLayoutHints(kLHintsCenterX, 2, 2, 2, 2));
// Sets window name and shows the main frame
SetWindowName("Simple Example");
MapSubwindows();
Resize(GetDefaultSize());
MapWindow();
}
void MyMainFrame::DoDraw() {
// Draws function graphics in randomly chosen interval
TF1* f1 = new TF1("f1", "sin(x)/x", 0, gRandom->Rndm() * 10);
f1->SetFillColor(19);
f1->SetFillStyle(1);
f1->SetLineWidth(3);
f1->Draw();
TCanvas* fCanvas = fEcanvas->GetCanvas();
fCanvas->cd();
fCanvas->Update();
}
MyMainFrame::~MyMainFrame() {
// Clean up used widgets: frames, buttons, layouthints
}
void MyMainFrame::doClose()
{
gApplication->Terminate(0);
}
RootProject.cpp
#include <TApplication.h>
#include <TF1.h>
#include <TRandom3.h>
#include "myFrame.h"
#include "ex2aLinkDef.h"
int main(int argc, char** argv)
{
TApplication theApp("App", &argc, argv);
new MyMainFrame(gClient->GetRoot(), 200, 200);
theApp.Run();
return 0;
}
Thanks!