Qt5在添加Q_OBJECT后发现老是编译出错的原因

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/xzq413520903/article/details/79554318

在Qt编写过程中,如多线程使用信号槽时,需要添加Q_OBJECT,但是在添加之后发现编译老会出错。如下:

class ThreadSxxx : public QThread
{
    Q_OBJECT
public: 
ThreadSxxx ();

signals:
    signaltrig();
}

编译后总是提示undefined reference to vtable for "xxxx"的错误问题。

    出现该错误的原因是此时的Q_OBJECT是半途加入的,你需要让项目重新加载编译,解决的办法是直接在.pro文件中随便改动一点东西,即使是随便加个空格都可以,此时再编译就可以通过。

    若没有这么做,即使你对整个项目进行清除再重新构建都是不行的。


展开阅读全文

编译出错,找不到原因

11-28

#includern#includernrnLRESULT CALLBACK WinHuaProc(rn HWND hwnd, // handle to windowrn UINT uMsg, // message identifierrn WPARAM wParam, // first message parameterrn LPARAM lParam // second message parameterrn);rnrnrnrnrnint WINAPI WinMain(rn HINSTANCE hInstance, // handle to current instancern HINSTANCE hPrevInstance, // handle to previous instancern LPSTR lpCmdLine, // command linern int nCmdShow // show statern)rnrn WNDCLASS wndclass;rn wndclass.cbClsExtra=0;rn wndclass.cbWndExtra=0;rn wndclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);rn wndclass.hCursor=LoadCursor(NULL,IDC_CROSS);rn wndclass.hIcon=LoadIcon(NULL,IDI_ERROR);rn wndclass.hInstance=hInstance;rn wndclass.lpfnWndProc=WinHuaProc;rn wndclass.lpszClassName="zhouxuehua";rn wndclass.lpszMenuName=NULL;rn wndclass.style=CS_HREDRAW | CS_VREDRAW;rn rn RegisterClass(&wndclass);rn HWND hwnd;rn hwnd=CreateWindow("zhouxuehua","zhouxuehuadddddd",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);rn ShowWindow(hwnd,SW_SHOWNORMAL);rn UpdateWindow(hwnd);rnrn MSG msg;rn while(GetMessage(&msg,NULL,0,0))rn rn TranslateMessage(&msg);rn DispatchMessage(&msg);rn rn return 0;rnrnrnrnLRESULT CALLBACK WinHuaProc(rn HWND hwnd, // handle to windowrn UINT uMsg, // message identifierrn WPARAM wParam, // first message parameterrn LPARAM lParam // second message parameterrn)rnrn switch(uMsg)rn rn case WM_CHAR:rn char szChar[20];rn sprintf(szChar,"char is %d",wParam);rn MessageBox(hwnd,szChar,"hua",0);rn break;rn case WM_LBUTTONDOWN:rn MessageBox(hwnd,"mouse click","mouse",0);rn HDC dc;rn dc=GetDC(hwnd);rn TextOut(dc,0,0,"hello everyone",strlen("hello everyone"));rn ReleaseDC(hwnd,dc);rn case WM_PAINT:rn HDC hdc;rn PAINTSTRUCT ps;rn hdc=BeginPaint(hwnd,&ps);rn TextOut(hdc,0,100,"神恩震在城",strlen("神恩震在城"));rn EndPaint(hwnd,&ps);rn break;rn case WM_CLOSE:rn if(IDYES==MessageBox(hwnd,"是否真的退出?","box",MB_YESNO))rn rn DestroyWindow(hwnd);rn rn break;rn case WM_DESTROY:rn PostQuitMessage(0);rn break;rn default:rn return DefWindowProc(hwnd,uMsg,wParam,lParam);rn rn return 0;rnrn rn rnrn rnrnrnrnrnrnrnrnrnrnrnrn 论坛

没有更多推荐了,返回首页