0

I'm trying to create/add a dialog to my application - To explain why the name of the dialog - it's to allow configuration/settings to be maintained such as themes/styles, and such so it's called SettingsDialog. For whatever reason, I'm getting no errors in the header file but I get errors in the cpp file - at first it was yelling at me that the constructor looked like a constructor but was not one or something like that - I seemed to fix that just by applying bodies to every other method (even though I've never got that error before). Now when I'm trying to create a QSplitter, it's telling me 'this' is not a QWidget when it refers to this class, a QDialog which according to the QT documentation is inherited from QWidget. I feel like there's a typo somewhere I'm missing maybe. Please I hope someone can see the blockage and help me resolve it.

Before anyone complains about it being not as simple as they'd like it - I include only the bare minimum methods and items - Every widget I create has an initPanel/Window/Dialog method and an initControls method that is called from the other init method after other configurations. As you can see, in the constructor, I call initDialog. I put my classes in a namespace - sure it may be a lot of white space but if by removing the namespace section it fixes it - that doesn't fix it for me - The namespaces are essential so I need a solution that keeps them in the code which is why I have not removed them. Otherwise, I can't strip anything else out. More will end up going in there eventually when I get this part to stop erroring in build, so cutting out the init methods even though they're not being called now won't help anything one bit.

SettingsDialog.h:

#pragma once #include <QDialog> #include <QSplitter> namespace net { namespace draconia { namespace mediadb { namespace ui { class SettingsDialog : public QDialog { Q_OBJECT QSplitter *mPnlSplitter; protected: QSplitter *getSplitter() const; void initControls(); void initDialog(); public: SettingsDialog(QWidget *parent = nullptr); }; } } } } 

SettingsDialog.cpp:

#include "SettingsDialog.h" using namespace net::draconia::mediadb::ui; QSplitter *SettingsDialog::getSplitter() const { if(mPnlSplitter == nullptr) { mPnlSplitter = new QSplitter(Qt::Orientation::Horizontal, this); // Error - no matching constructors evidently } } void SettingsDialog::initControls() { } void SettingsDialog::initDialog() { } SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent) , mPnlSplitter(nullptr) { initDialog(); } 

1 Answer 1

2
  1. You try to change the mPnlSplitter member in the const getSplitter() method.
  2. QSplitter's constructor accepts QWidget *, not const QWidget *

Also note that QSplitter *SettingsDialog::getSplitter() const should return a value, but there is no return in the method.

Sign up to request clarification or add additional context in comments.

1 Comment

You are a godsend! I took off "const" at the end in both the header and cpp file and it fixed it - I have a tendency to put const on the end for getters without thinking about the fact that I'm using lazy creation. I was racking my brain about this. Thank you so much! I upvoted the answer but is there anything else I need to do to mark this answer as a good answer?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.