I have a form that was giving me a SegFault Exception so I broke it down and commented out everything but the mainwindow itself. Then I uncommented out the first 2 controls to display. I'm using a qgridlayout but it's not showing things correctly. When I show just the first item, it shows the label with the & instead of an underline - which makes sense since I don't show the "buddy". If I show both though or if I add the 'setBuddy' in then the buddy overwrites the label in the grid at 0,0. The label is supposed to be at 0,0 and the buddy/combo box is at 0, 1. I need to keep adding things in and my alternative is to use QHBoxLayouts repeatedly and I'm not nuts about that at all as things won't be aligned. Here's just the CPP code for the MainWindow to see:
QComboBox *MainWindow::getSourceComboBox()
{
if(mCboSource == nullptr)
{
mCboSource = new QComboBox(this);
mCboSource->addItems({{"URL", "Text", "Database"}});
mCboSource->setCurrentIndex(0);
mCboSource->setEditable(false);
//connect(mCboSource, SIGNAL(QComboBox::currentTextChanged(QString &)), this, SLOT(MainWindow::sourceChanged(QString &)));
}
return(mCboSource);
}
QLabel *MainWindow::getSourceLabel()
{
if(mLblSource == nullptr)
{
mLblSource = new QLabel("&Source:", this);
mLblSource->setBuddy(getSourceComboBox());
mLblSource->setAutoFillBackground(false);
}
return(mLblSource);
}
void MainWindow::initControls()
{
QGridLayout *layout = new QGridLayout(this);
layout->addWidget(this->getSourceLabel(), 0, 0, 1, 1);
layout->addWidget(this->getSourceComboBox(), 0, 1, 1, 1);
/*layout->addWidget(this->getConfigButton(), 0, 2);
layout->addWidget(this->getDBPathLabel(), 1, 0);
layout->addWidget(this->getDBPathText(), 1, 1);
layout->addWidget(this->getBrowseButton(), 1, 2);
layout->addWidget(this->getDataTable(), 2, 0, 1, 3);
layout->addWidget(this->getButtonPanel(), 3, 0, 1, 3);*/
setLayout(layout);
}
void MainWindow::initWindow()
{
setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
initControls();
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, mCboSource(nullptr)
//, mLblDBPath(nullptr)
, mLblSource(nullptr)
/*, mTxtDBPath(nullptr)
, mBtnBrowse(nullptr)
, mBtnConfig(nullptr)
, mTblData(nullptr)*/
{
initWindow();
}
MainWindow::~MainWindow()
{ }
But what could be wrong w/ the QT code???