问题一。在QT中怎么捕获到XP系统的休眠事件
问题二。一个对话框类与一线程类,在线程类中调用对话框类,可当运行到 exec()时就会报错,代码如下:请指教,谢谢
class CDialogWin : public QDialog
{
Q_OBJECT
private:
QVBoxLayout* m_pMainLayout;
QLabel* m_pLabel;
void NewWinEvent(QString str);
};
CDialogWin::CDialogWin():m_pMainLayout(NULL),m_pLabel(NULL)
{
setWindowTitle("3G MODEM");
m_pMainLayout = new QVBoxLayout;
m_pLabel = new QLabel;
QHBoxLayout *pUpLayout = new QHBoxLayout;
pUpLayout->addWidget(m_pLabel);
m_pMainLayout->addLayout(pUpLayout);
setLayout(m_pMainLayout);
}
void CDialogWin::NewWinEvent(QString str)
{
m_pLabel->setText(str);
}
class CDialogThread : public QThread
{
Q_OBJECT
private:
CDialogWin* m_pDilog; //对话框类指针
QString m_Str; //存储字符串
void GetDilogInstance(QString str);
void run();
};
CDialogThread::CDialogThread()
{
m_pDilog = new CDialogWin();
}
void CDialogThread::GetDilogInstance(QString str)
{
m_Str = str;
if(!isRunning())
{
start();
}
}
void void CDialogThread::run()
{
m_pDilog->NewWinEvent(m_Str);
m_pDilog->exec(); -----> 在这里报错,不知原因
}
int main()
{
CDialogThread* p = new CDialogThread();
p->GetDilogInstance("hello world");
}
错误:Debug Error!
Program: c:\qt\hWalk.exe
This application has requested the Runtime to terminate it an unusual way.
Please contact the application's support team for more information.
终止 重试 忽略
------解决方案--------------------
不要在Qt里混用Windows的MFC。
Qt是跨平台的GUI框架,里边已经有Windows的代码了。
忘记Windows的MFC,照着Qt的框架写代码吧。
------解决方案--------------------
------解决方案--------------------
7楼已经说的很清楚了,Qt没有这个能力,你需要使用Win32 API。