Write your question here.
Please help C++ greenhorn navigate the task and learn how to pass pointers to an object.
My objective is to put an information in main window - GUI dialog.
I have build a class to access the required information and added the class / object to main window.
CCC_LocalAdapters *LocalAdapters = new CCC_LocalAdapters();
The info is retrieved by method which returns a pointer to the info and accessed by this line of code – which is wrong for my task :
LocalAdapters.LocalAdapter();
I cannot figure out how to make the info – which is for now a local variable in
LocalAdapter() method accessible in main window via a pointer.
My guess is I need to rebuild the constructor of the CCC_LocalAdapters() to include a pointer.
Here are the main and CCC_LocalAdapters() constructors :
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
…
CCC_LocalAdapters *LocalAdapters = new LocalAdapter(????);
}
CCC_LocalAdapters::CCC_LocalAdapters(QObject *parent) : QObject(parent)
{
// bluetooth test for local device - works as expected
QList<QBluetoothHostInfo> infos = QBluetoothLocalDevice::allDevices();
…
}
In not so technical terms – I need to pass “infos” upstream so I can let main
window GUI print it.
I’ll be happy if pointed to some decent tutorial about the “passing pointers to objects” in C++ .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
…
CCC_LocalAdapters *LocalAdapters = new LocalAdapter(????);
}
CCC_LocalAdapters::CCC_LocalAdapters(QObject *parent) : QObject(parent)
{
// bluetooth test for local device - works as expected
QList<QBluetoothHostInfo> infos = QBluetoothLocalDevice::allDevices();
…
}
| |