LNK2019 error while importing functions from different class

  • I wanted to access the functions in qSlicerApplication and qSlicerLayoutManager in qMRMLThreeDViewControllerWidget class.

  • when a Button in qMRMLThreeDViewControllerWidget is clicked an action ViewLayoutOneUp3DAction should be triggred.

  • Includes:

#include "../../../Base/QTGUI/qSlicerApplication.h"
#include "../../../Base/QTGUI/qSlicerLayoutManager.h"
  • code for QToolButton in qMRMLThreeDViewControllerWidget.cxx :
  void qMRMLThreeDViewControllerWidgetPrivate::init()
{
  Q_Q(qMRMLThreeDViewControllerWidget);
  this->Superclass::init();

  q->setupMenuActions();

  this->CenterToolButton = new QToolButton(q);
  this->CenterToolButton->setAutoRaise(true);
  this->CenterToolButton->setDefaultAction(this->ViewLayoutOneUp3DAction);
  this->CenterToolButton->setFixedSize(15, 15);
  this->BarLayout->insertWidget(2, this->CenterToolButton); 
}

void qMRMLThreeDViewControllerWidget::setupMenuActions() {
    Q_D(qMRMLThreeDViewControllerWidget);
    d->ViewLayoutOneUp3DAction->setData(vtkMRMLLayoutNode::SlicerLayoutOneUp3DView);
}

void qMRMLThreeDViewControllerWidgetPrivate::setupPopupUi()
{
  Q_Q(qMRMLThreeDViewControllerWidget);

  this->Superclass::setupPopupUi();

QObject::connect(this->ViewLayoutOneUp3DAction, SIGNAL(triggered(QAction*)),
                   q, SLOT(ThreeDViewOnly(QAction*)));
}

void qMRMLThreeDViewControllerWidget::ThreeDViewOnly(QAction* action)
{
    this->setLayout(action->data().toInt());
}

void qMRMLThreeDViewControllerWidget::setLayout(int layout)
{
    qSlicerApplication::application()->layoutManager()->setLayout(layout);
}
  • Declaration in qMRMLThreeDViewControllerWidget.h:
Public slots:
 virtual void ThreeDViewOnly(QAction* action);
 virtual void setLayout(int);

protected:
    virtual void setupMenuActions();

  • Error encountered:
![Screenshot (326)|690x153](upload://eRFkvTJKPRV2gd3jRz8SeWJR7VS.png)

MRML is an independent library from Slicer. You cannot call any qSlicer… classes from qMRML… classes, because MRML does not know about Slicer. The original reason to keep MRML library independent from Slicer is to allow building other applications from it, but this modulatization also makes the code easier to maintain and for example distribute MRML as an independent Python package.

This just means that you are not allowed to call Slicer methods from MRML classes, but you can still emit events from MRML classes that the application can process. See for example how node editing is implemented (search for nodeedit in the Slicer source code).

I guess you are trying to implement the maximize view feature. We would like to have this in Slicer core and it would be great if you could contribute it - it would save us implementation time and it would save you maintenance time. Temporarily maximizing a view could be implemented as a function in the layout manager: when the maximize button is clicked in a view controller then the layout manager would hide (not remove) all the other view widgets, which would make the selected view widget take the entire layout space. qMRMLLayoutManager is in MRML, so you would probably you could use direct methods calls (would not need to communicate through events).

10 posts were split to a new topic: Add button to maximize view