• 19607阅读
  • 15回复

qt 自定义窗口部件 在ui文件中找不到"xxxx.h" [复制链接]

上一主题 下一主题
离线xiexiaoping
 

只看楼主 倒序阅读 楼主  发表于: 2010-11-10
— 本帖被 XChinux 执行加亮操作(2010-11-11) —
我以插件的形式自定义了一个窗口部件,在qt  Designer中,设计窗体时,把该部件拖到窗体上去。
编译时,在ui文件中说找不到”xxxx.h“文件。
我知道的解决方法1:把插件的工程文件拷到应用程序目录里面,然后把插件头文件引进去就可以。
但是,我不想通过此方法,因为我有很多个工程都会用到此部件插件,一个一个引得话太麻烦。

问:有没有办法把插件的头文件放到Qt的安装目录里面去,让编译器自动能够找到头文件?
离线dbzhang800

只看该作者 1楼 发表于: 2010-11-10
头文件目录不就是 %QTDIR%/include 么?你放进去不就完了?
离线xiexiaoping

只看该作者 2楼 发表于: 2010-11-11
回 1楼(dbzhang800) 的帖子
直接放放进头文件,好像不行。
离线dbzhang800

只看该作者 3楼 发表于: 2010-11-11
Re:回 1楼(dbzhang800) 的帖子
引用第2楼xiexiaoping于2010-11-11 09:20发表的 回 1楼(dbzhang800) 的帖子 :
直接放放进头文件,好像不行。

具体现象是什么?
离线xiexiaoping

只看该作者 4楼 发表于: 2010-11-11
回 3楼(dbzhang800) 的帖子
我用的是Qt Gui 4书里面的iconeditorplugin部件插件,然后我把此部件拖到主窗体上。
编译的时候就出以下的错误。
mingw32-make[1]: *** No rule to make target `iconeditor.h', needed by `ui_mainwindow.h'. Stop.

我知道的解决办法是:工程文件拷到应用程序目录里面,然后把插件头文件引进去就可以。

但是我不想通过此方法解决,因为我有很多工程,如果一个一个加的话太麻烦。
把`iconeditor.h 加入到%QTDIR%/include中去,照样出现
mingw32-make[1]: *** No rule to make target `iconeditor.h', needed by `ui_mainwindow.h'. Stop. 错误
离线dbzhang800

只看该作者 5楼 发表于: 2010-11-11
我没用designer的插件,不太了解具体情况。

但仅仅一个头文件,怎么会成了target呢 ?莫非你通过某种方式把它加到你的 pro 文件内了?

不然的话,qmake 是老老实实根据 pro 来生成 makefile 文件(该makefile文件中不可能生成这个  target)
离线xiexiaoping

只看该作者 6楼 发表于: 2010-11-11
我没有加到pro里面,dbzhang800你可以做个小例子试一试,帮我看看到底是什么原因。
离线dbzhang800

只看该作者 7楼 发表于: 2010-11-11
贴一下你的pro文件和makefile(.debug或release)文件吧
离线xiexiaoping

只看该作者 8楼 发表于: 2010-11-11
回 7楼(dbzhang800) 的帖子
QT       += core gui
TARGET = CjcpLabel
TEMPLATE = app
SOURCES += main.cpp\
        mainwindow.cpp
HEADERS  += mainwindow.h
FORMS    += mainwindow.ui




#############################################################################
# Makefile for building: CjcpLabel
# Generated by qmake (2.01a) (Qt 4.6.3) on: ??? ??? 11 14:10:10 2010
# Project:  CjcpLabel.pro
# Template: app
#############################################################################

####### Compiler, tools and options

CC            = gcc
CXX           = g++
DEFINES       = -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN
CFLAGS        = -g -Wall $(DEFINES)
CXXFLAGS      = -g -frtti -fexceptions -mthreads -Wall $(DEFINES)
INCPATH       = -I"d:\Qt\2010.04\qt\include\QtCore" -I"d:\Qt\2010.04\qt\include\QtGui" -I"d:\Qt\2010.04\qt\include" -I"d:\Qt\2010.04\qt\include\ActiveQt" -I"debug" -I"." -I"d:\Qt\2010.04\qt\mkspecs\win32-g++"
LINK        =        g++
LFLAGS        =        -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows
LIBS        =        -L"d:\Qt\2010.04\qt\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4
QMAKE         = d:\qt\2010.04\qt\bin\qmake.exe
IDC           = d:\Qt\2010.04\qt\bin\idc.exe
IDL           = midl
ZIP           = zip -r -9
DEF_FILE      =
RES_FILE      =
COPY          = copy /y
COPY_FILE     = $(COPY)
COPY_DIR      = xcopy /s /q /y /i
DEL_FILE      = del
DEL_DIR       = rmdir
MOVE          = move
CHK_DIR_EXISTS= if not exist
MKDIR         = mkdir
INSTALL_FILE    = $(COPY_FILE)
INSTALL_PROGRAM = $(COPY_FILE)
INSTALL_DIR     = $(COPY_DIR)

####### Output directory

OBJECTS_DIR   = debug

####### Files

SOURCES       = main.cpp \
        mainwindow.cpp debug\moc_mainwindow.cpp
OBJECTS       = debug/main.o \
        debug/mainwindow.o \
        debug/moc_mainwindow.o
DIST          =
QMAKE_TARGET  = CjcpLabel
DESTDIR        = debug\ #avoid trailing-slash linebreak
TARGET         = CjcpLabel.exe
DESTDIR_TARGET = debug\CjcpLabel.exe

####### Implicit rules

.SUFFIXES: .cpp .cc .cxx .c

.cpp.o:
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.cc.o:
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.cxx.o:
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.c.o:
    $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<

####### Build rules

first: all
all: Makefile.Debug  $(DESTDIR_TARGET)

$(DESTDIR_TARGET): ui_mainwindow.h $(OBJECTS)
    $(LINK) $(LFLAGS) -o $(DESTDIR_TARGET) $(OBJECTS)  $(LIBS)


qmake:  FORCE
    @$(QMAKE) -spec d:\Qt\2010.04\qt\mkspecs\win32-g++ -win32 -o Makefile.Debug CjcpLabel.pro

dist:
    $(ZIP) CjcpLabel.zip $(SOURCES) $(DIST) CjcpLabel.pro d:\Qt\2010.04\qt\mkspecs\qconfig.pri d:\Qt\2010.04\qt\mkspecs\features\qt_functions.prf d:\Qt\2010.04\qt\mkspecs\features\qt_config.prf d:\Qt\2010.04\qt\mkspecs\features\exclusive_builds.prf d:\Qt\2010.04\qt\mkspecs\features\default_pre.prf d:\Qt\2010.04\qt\mkspecs\features\win32\default_pre.prf d:\Qt\2010.04\qt\mkspecs\features\debug.prf d:\Qt\2010.04\qt\mkspecs\features\debug_and_release.prf d:\Qt\2010.04\qt\mkspecs\features\default_post.prf d:\Qt\2010.04\qt\mkspecs\features\win32\default_post.prf d:\Qt\2010.04\qt\mkspecs\features\build_pass.prf d:\Qt\2010.04\qt\mkspecs\features\win32\rtti.prf d:\Qt\2010.04\qt\mkspecs\features\win32\exceptions.prf d:\Qt\2010.04\qt\mkspecs\features\win32\stl.prf d:\Qt\2010.04\qt\mkspecs\features\shared.prf d:\Qt\2010.04\qt\mkspecs\features\warn_on.prf d:\Qt\2010.04\qt\mkspecs\features\qt.prf d:\Qt\2010.04\qt\mkspecs\features\win32\thread.prf d:\Qt\2010.04\qt\mkspecs\features\moc.prf d:\Qt\2010.04\qt\mkspecs\features\win32\windows.prf d:\Qt\2010.04\qt\mkspecs\features\resources.prf d:\Qt\2010.04\qt\mkspecs\features\uic.prf d:\Qt\2010.04\qt\mkspecs\features\yacc.prf d:\Qt\2010.04\qt\mkspecs\features\lex.prf d:\Qt\2010.04\qt\mkspecs\features\include_source_dir.prf d:\Qt\2010.04\qt\lib\qtmaind.prl  HEADERS RESOURCES IMAGES SOURCES OBJECTIVE_SOURCES FORMS YACCSOURCES YACCSOURCES LEXSOURCES

clean: compiler_clean
    -$(DEL_FILE) debug\main.o debug\mainwindow.o debug\moc_mainwindow.o

distclean: clean
    -$(DEL_FILE) $(DESTDIR_TARGET)
    -$(DEL_FILE) Makefile.Debug

check: first

mocclean: compiler_moc_header_clean compiler_moc_source_clean

mocables: compiler_moc_header_make_all compiler_moc_source_make_all

compiler_moc_header_make_all: debug/moc_mainwindow.cpp
compiler_moc_header_clean:
    -$(DEL_FILE) debug\moc_mainwindow.cpp
debug/moc_mainwindow.cpp: mainwindow.h
    D:\Qt\2010.04\qt\bin\moc.exe $(DEFINES) $(INCPATH) -D__GNUC__ -DWIN32 mainwindow.h -o debug\moc_mainwindow.cpp

compiler_rcc_make_all:
compiler_rcc_clean:
compiler_image_collection_make_all: qmake_image_collection.cpp
compiler_image_collection_clean:
    -$(DEL_FILE) qmake_image_collection.cpp
compiler_moc_source_make_all:
compiler_moc_source_clean:
compiler_uic_make_all: ui_mainwindow.h
compiler_uic_clean:
    -$(DEL_FILE) ui_mainwindow.h
ui_mainwindow.h: mainwindow.ui
    d:\Qt\2010.04\qt\bin\uic.exe mainwindow.ui -o ui_mainwindow.h

compiler_yacc_decl_make_all:
compiler_yacc_decl_clean:
compiler_yacc_impl_make_all:
compiler_yacc_impl_clean:
compiler_lex_make_all:
compiler_lex_clean:
compiler_clean: compiler_moc_header_clean compiler_uic_clean



####### Compile

debug/main.o: main.cpp mainwindow.h
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o debug\main.o main.cpp

debug/mainwindow.o: mainwindow.cpp mainwindow.h \
        ui_mainwindow.h
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o debug\mainwindow.o mainwindow.cpp

debug/moc_mainwindow.o: debug/moc_mainwindow.cpp
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o debug\moc_mainwindow.o debug\moc_mainwindow.cpp

####### Install

install:   FORCE

uninstall:   FORCE

FORCE:


帮忙看看,谢谢啦!
离线xiexiaoping

只看该作者 9楼 发表于: 2010-11-11
to  dbzhang800
你好!你qq多少?
离线dbzhang800

只看该作者 10楼 发表于: 2010-11-11
看起来应该没什么问题

不妨贴一下具体的出错信息,看看那条指令导致的问题
离线xiexiaoping

只看该作者 11楼 发表于: 2010-11-11
回 10楼(dbzhang800) 的帖子
我把iconeditor.h文件放到qt include底下编译时
出现下面的错误信息
debug/mainwindow.o:E:\QtTest\CjcpLabel/ui_mainwindow.h:43: undefined reference to `IconEditor::IconEditor(QWidget*)'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\CjcpLabel.exe] Error 1
mingw32-make: *** [debug] Error 2
The process "D:/Qt/2010.04/mingw/bin/mingw32-make.exe" exited with code %2.
Error while building project CjcpLabel (target: Desktop)
When executing build step 'Make'
离线dbzhang800

只看该作者 12楼 发表于: 2010-11-11
Re:回 10楼(dbzhang800) 的帖子
引用第11楼xiexiaoping于2010-11-11 14:34发表的 回 10楼(dbzhang800) 的帖子 :
我把iconeditor.h文件放到qt include底下编译时
出现下面的错误信息
debug/mainwindow.o:E:\QtTest\CjcpLabel/ui_mainwindow.h:43: undefined reference to `IconEditor::IconEditor(QWidget*)'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\CjcpLabel.exe] Error 1
.......

汗,你早贴这个不就完了。前面你贴的编译问题。现在这个是链接问题,去把你的库在pro文件内加上
离线xiexiaoping

只看该作者 13楼 发表于: 2010-11-11
回 12楼(dbzhang800) 的帖子
你好!怎么加啊。
这下面2个文件
iconeditorplugin.dll
libiconeditorplugin.a
插件生成的位置在qt\plugins\designer底下
离线dbzhang800

只看该作者 14楼 发表于: 2010-11-11
Re:回 12楼(dbzhang800) 的帖子
引用第13楼xiexiaoping于2010-11-11 15:08发表的 回 12楼(dbzhang800) 的帖子 :
你好!怎么加啊。
这下面2个文件
iconeditorplugin.dll
libiconeditorplugin.a
插件生成的位置在qt\plugins\designer底下

和插件没有任何关系了(插件的作用只不过是在 designer 中显示一下)。一旦离开designer就要彻底忘记它。

你写一个widget,典型的不就是一个 xxx.h 和 xxx.cpp 文件么?

这个两个文件怎么用,不就是直接加入工程,或者编译成库(动态或静态)配合头文件再使用么?

现在头文件你放进include目录了,那你的 lib 呢?你准备放进 %QTDIR%/lib 还是其他目录?

概念清楚是最重要的。
离线xiexiaoping

只看该作者 15楼 发表于: 2010-11-11
回 14楼(dbzhang800) 的帖子
谢谢 dbzhang800的指导,我已经知道怎么做了。
快速回复
限100 字节
 
上一个 下一个