Qt creator 9.0.1 Header file QtNetwork file not found.
-
Hi everyone. I'm running qtcreator 9.0.1 on Ubuntu 22.04 (from the qt installer not apt) and if I try and include QtNetwork in a QT6 project, it says file not found. If I open a example network program, no error.
Please help.
Cheers,
John T -
Hi everyone. I'm running qtcreator 9.0.1 on Ubuntu 22.04 (from the qt installer not apt) and if I try and include QtNetwork in a QT6 project, it says file not found. If I open a example network program, no error.
Please help.
Cheers,
John T@John-Telek Did you add
find_package(Qt6 REQUIRED COMPONENTS Network) target_link_libraries(mytarget PRIVATE Qt6::Network)
to your CMakeLists.txt in case you're using CMake
OrQT += network
if you're using QMake?
-
I added it and got this error.
/home/user/Code/QT/TCOM3/CMakeLists.txt:15: error: Cannot specify link libraries for target "mytarget" which is not built by this project.
anything else I could look at. I'm a complete newbie to programming and C++.
Cheers,
John -
I added it and got this error.
/home/user/Code/QT/TCOM3/CMakeLists.txt:15: error: Cannot specify link libraries for target "mytarget" which is not built by this project.
anything else I could look at. I'm a complete newbie to programming and C++.
Cheers,
John@John-Telek Your CMakeLists.txt is wrong. Please post it.
-
My CmakeLists
cmake_minimum_required(VERSION 3.5) project(TCOM3 VERSION 0.1 LANGUAGES CXX) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Gui Network Widgets) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) set(PROJECT_SOURCES main.cpp mainwindow.cpp mainwindow.h mainwindow.ui ) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(TCOM3 MANUAL_FINALIZATION ${PROJECT_SOURCES} ) # Define target properties for Android with Qt 6 as: # set_property(TARGET TCOM3 APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR # ${CMAKE_CURRENT_SOURCE_DIR}/android) # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation else() if(ANDROID) add_library(TCOM3 SHARED ${PROJECT_SOURCES} ) # Define properties for Android with Qt 5 after find_package() calls as: # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") else() add_executable(TCOM3 ${PROJECT_SOURCES} ) endif() endif() target_link_libraries(TCOM3 PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) set_target_properties(TCOM3 PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) install(TARGETS TCOM3 BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) if(QT_VERSION_MAJOR EQUAL 6) qt_finalize_executable(TCOM3) endif()
Cheers
-
@John-Telek said in Qt creator 9.0.1 Header file QtNetwork file not found.:
/home/user/Code/QT/TCOM3/CMakeLists.txt:15: error: Cannot specify link libraries for target "mytarget" which is not built by this project.
You need to replace
mytarget
with the CMake target that you're defining in the CMakeLists.txt file. That is, if you have a line likeadd_executable(somename ...)
or add_library(somename ...)
Then
somename
is the CMake target name you want to use, instead ofmytarget
. -
I did and still get this error.
/home/user/Code/QT/TCOM3/CMakeLists.txt:15: error: Cannot specify link libraries for target "TCOM3" which is not built by this project.
The name is correct. And I still dont understand why #include <QtNetwork> and #include <QTcpSocket> only work in the examples.
Cheers
-
I did and still get this error.
/home/user/Code/QT/TCOM3/CMakeLists.txt:15: error: Cannot specify link libraries for target "TCOM3" which is not built by this project.
The name is correct. And I still dont understand why #include <QtNetwork> and #include <QTcpSocket> only work in the examples.
Cheers
@John-Telek Please post your current CMakeLists.txt file.
"And I still dont understand why #include <QtNetwork> and #include <QTcpSocket> only work in the examples" - did you compare your CMakeLists.txt with the one from example? -
Now none of my base code will compile. Keep getting a Ninja -C error.
JT
-
Now none of my base code will compile. Keep getting a Ninja -C error.
JT
@John-Telek Make a complete rebuild: delete everything in build folder (including hidden files), run CMake and build.
In case of error message post it here. -
@John-Telek said in Qt creator 9.0.1 Header file QtNetwork file not found.:
/home/user/Code/QT/TCOM3/CMakeLists.txt:15: error: Cannot specify link libraries for target "mytarget" which is not built by this project.
You need to replace
mytarget
with the CMake target that you're defining in the CMakeLists.txt file. That is, if you have a line likeadd_executable(somename ...)
or add_library(somename ...)
Then
somename
is the CMake target name you want to use, instead ofmytarget
.@kkoehne said in Qt creator 9.0.1 Header file QtNetwork file not found.:
@John-Telek said in Qt creator 9.0.1 Header file QtNetwork file not found.:
/home/user/Code/QT/TCOM3/CMakeLists.txt:15: error: Cannot specify link libraries for target "mytarget" which is not built by this project.
You need to replace
mytarget
with the CMake target that you're defining in the CMakeLists.txt file. That is, if you have a line likeadd_executable(somename ...)
or add_library(somename ...)
Then
somename
is the CMake target name you want to use, instead ofmytarget
.please explain "somename" more
-
@kkoehne said in Qt creator 9.0.1 Header file QtNetwork file not found.:
@John-Telek said in Qt creator 9.0.1 Header file QtNetwork file not found.:
/home/user/Code/QT/TCOM3/CMakeLists.txt:15: error: Cannot specify link libraries for target "mytarget" which is not built by this project.
You need to replace
mytarget
with the CMake target that you're defining in the CMakeLists.txt file. That is, if you have a line likeadd_executable(somename ...)
or add_library(somename ...)
Then
somename
is the CMake target name you want to use, instead ofmytarget
.please explain "somename" more
@micha_eleric "somename" is a placeholder for the name you gave CMake for your executable or library in CMakeLists.txt. This name will appear in one of these directives:
add_executable(somename ...) add_library(somename ....) qt_add_executable(somename ....) qt_add_library(somename ...)
-
@micha_eleric "somename" is a placeholder for the name you gave CMake for your executable or library in CMakeLists.txt. This name will appear in one of these directives:
add_executable(somename ...) add_library(somename ....) qt_add_executable(somename ....) qt_add_library(somename ...)
@ChrisW67 said in Qt creator 9.0.1 Header file QtNetwork file not found.:
@micha_eleric "somename" is a placeholder for the name you gave CMake for your executable or library in CMakeLists.txt. This name will appear in one of these directives:
add_executable(somename ...) add_library(somename ....) qt_add_executable(somename ....) qt_add_library(somename ...)
i assumed that "somename" was a placeholder for project name, but gives same error, but with project name instead.
-
@ChrisW67 said in Qt creator 9.0.1 Header file QtNetwork file not found.:
@micha_eleric "somename" is a placeholder for the name you gave CMake for your executable or library in CMakeLists.txt. This name will appear in one of these directives:
add_executable(somename ...) add_library(somename ....) qt_add_executable(somename ....) qt_add_library(somename ...)
i assumed that "somename" was a placeholder for project name, but gives same error, but with project name instead.
@micha_eleric Please show your current CMakeLists.txt file.
Also, you should do complete rebuild after changing CMakeLists.txt