我需要將StorageSCP類中的loadReceivedFiles()
信號鏈接到MainController中的test()
插槽。如何獲得在Qt中工作的信號和插槽?
下面的代碼給了我3個錯誤:
connect(storageSCPWorker->getStorageSCP, &StorageSCP::loadReceivedFiles, this, &MainController::test);
錯誤2錯誤C2248:'的QObject :: QObject的:不能訪問類的QObject的'C聲明私有成員 :\用戶\ 310214192 \文檔\ Visual工作室 2012 \項目\測試\測試\ storagescp.h 18 1測試
錯誤3錯誤C2248: 'SCP :: SCP':不能訪問類中聲明 'SCP的' C私有成員 :\ users \ 310214192 \ documents \ visual studio 2012 \ projects \ Test \ Test \ storagescp.h 18 1測試
錯誤1錯誤C3867:'StorageSCPWorker :: getStorageSCP':函數調用 缺少參數列表;使用 '& StorageSCPWorker :: getStorageSCP' 到 創建一個指向成員C:\用戶\ 310214192個\文檔\ Visual Studio的 2012 \項目\測試\測試\ maincontroller.cpp 10 1測試
我怎樣才能得到這個工作?
MainController.cpp:
MainController::MainController()
{
storageSCPWorkerThread = new QThread();
storageSCPWorker = new StorageSCPWorker(104, "AE_TEST", 16384, "C:/Test/Received/");
storageSCPWorker->moveToThread(storageSCPWorkerThread);
connect(storageSCPWorkerThread, &QThread::started, storageSCPWorker, &StorageSCPWorker::startSCP);
//connect(storageSCPWorker->getStorageSCP, &StorageSCP::loadReceivedFiles, this, &MainController::test);
storageSCPWorkerThread->start();
}
void MainController::test()
{
qDebug() << "HELLO MOTO!!!!";
}
MainController.h:
class MainController : public QObject
{
Q_OBJECT
public:
MainController();
~MainController();
public slots:
void test();
private:
QThread* storageSCPWorkerThread;
StorageSCPWorker* storageSCPWorker;
};
StorageSCPWorker.cpp:
StorageSCP StorageSCPWorker::getStorageSCP()
{
return storageSCP;
}
StorageSCPWorker.h:
class StorageSCPWorker : public QObject
{
Q_OBJECT
public:
StorageSCPWorker(int port, const OFString &aeTitle, int maxPduLength, const OFString &outputDirectory);
~StorageSCPWorker();
StorageSCP getStorageSCP();
public slots:
void startSCP();
private:
int port;
OFString aeTitle;
int maxPduLength;
OFString outputDirectory;
StorageSCP storageSCP;
OFCondition status;
};
StorageSCP.cpp:
void StorageSCP::notifyInstanceStored()
{
emit loadReceivedFiles();
}
StorageSCP.h:
signals:
void loadReceivedFiles();
'StorageSCP getStorageSCP();'你返回件的複印件。這很可能不是你想要的行爲。返回(const)引用。 –