Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[newbie] visibility among files

24 views
Skip to first unread message

Soviet_Mario

unread,
Jun 30, 2018, 6:18:50 PM6/30/18
to
I left C++ quite some years ago and now that I'm beginning
again (QT Creator IDE) I can no longer have control over
scope among files.

I was used to separate code in different files, but it seems
that I have some wrong setting (maybe in the makefile
self-generated by QT, the errors are on linking)

I've tried to include the .CPP files besides the normal .H
files (with the normal protection against multiple
inclusion, #ifndef #define #endif) but this still does not work.

The classes defined in a separate file (added to the project
tree) are not visible neither in the MAIN.CPP nor in the
MAINWINDOW.CPP, the two files generated as the minimal project.

I have a feeble memory that if not defined static in a file,
or hidden in an anonimous namespace, classes and variable
declared in file scope would be visible out.

No modifier (public) is allowed in the class opening
declaration.

Are there some import/export directives ? Pls help

Oh, err, and speaking of QT Creator IDE (for linux) I can't
find the tab where to define the include paths ...

TY


--
1) Resistere, resistere, resistere.
2) Se tutti pagano le tasse, le tasse le pagano tutti
Soviet_Mario - (aka Gatto_Vizzato)

Öö Tiib

unread,
Jul 2, 2018, 2:44:45 AM7/2/18
to
On Sunday, 1 July 2018 01:18:50 UTC+3, Soviet_Mario wrote:
> I left C++ quite some years ago and now that I'm beginning
> again (QT Creator IDE) I can no longer have control over
> scope among files.
>
> I was used to separate code in different files, but it seems
> that I have some wrong setting (maybe in the makefile
> self-generated by QT, the errors are on linking)
>
> I've tried to include the .CPP files besides the normal .H
> files (with the normal protection against multiple
> inclusion, #ifndef #define #endif) but this still does not work.

Qt is framework where we have to use (somewhat crippling) extension of
C++ that the framework preprocesses into actual C++. It is done by utility
called qmake. You need to indicate to qmake what files are in your project
with a .pro file. I take random one from my hard drive:

#-------------------------------------------------
#
# Project created by QtCreator 2014-11-20T06:42:24
#
#-------------------------------------------------

QT += core

QT -= gui


TARGET = MasterMind
CONFIG += console
CONFIG += c++11
CONFIG -= app_bundle

QMAKE_CXXFLAGS += -ftemplate-depth-5000 -fconstexpr-depth=5000

QMAKE_LFLAGS += -Wl,--stack,4194304

TEMPLATE = app

SOURCES += main.cpp \
Pattern.cpp

HEADERS += \
Peg.h \
Pattern.h

The point is to illustrate how one defines to qmake what .cpp and .h
files are in a little project. So if you want to #include .cpp
files then you should perhaps list those as HEADERS.

I did compare constexpr doing lot of things compile-time versus highly
recursive code and so the QMAKE_CXXFLAGS and QMAKE_LFLAGS were altered
for to allow unusual template, constexpr and stack depths, you likely
don't need those settings. BTW I was convinced that constexpr works
with Qt and is indeed a killer winner in runtime perfomance but causes
horrible compile-times. ;)

Better answers you will get in some Qt-related forums. Qt is compiling
something that is not actually standard C++ and so is not strictly
topical here.

Soviet_Mario

unread,
Jul 2, 2018, 7:38:18 PM7/2/18
to
Il 02/07/2018 08:44, Öö Tiib ha scritto:
> On Sunday, 1 July 2018 01:18:50 UTC+3, Soviet_Mario wrote:
>> I left C++ quite some years ago and now that I'm beginning
>> again (QT Creator IDE) I can no longer have control over
>> scope among files.
>>
>> I was used to separate code in different files, but it seems
>> that I have some wrong setting (maybe in the makefile
>> self-generated by QT, the errors are on linking)
>>
>> I've tried to include the .CPP files besides the normal .H
>> files (with the normal protection against multiple
>> inclusion, #ifndef #define #endif) but this still does not work.
>
> Qt is framework where we have to use (somewhat crippling) extension of
> C++ that the framework preprocesses into actual C++. It is done by utility
> called qmake. You need to indicate to qmake what files are in your project
> with a .pro file. I take random one from my hard drive:

In another strictly related thread I pasted the .pro file

uh I forgot the PROJECT file (generated by QT Creator)

#-------------------------------------------------
#
# Project created by QtCreator 2018-06-21T16:21:34
#
#-------------------------------------------------

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Prova_QT_00
TEMPLATE = app


SOURCES +=\
main.cpp \
mainwindow.cpp \
disk_scanner_07.cpp

HEADERS += mainwindow.h \
disk_scanner_05.h

FORMS += mainwindow.ui

it seems to contain everything, nevertheless the errors :\


>
> #-------------------------------------------------
> #
> # Project created by QtCreator 2014-11-20T06:42:24
> #
> #-------------------------------------------------
>
> QT += core
>
> QT -= gui
>
>
> TARGET = MasterMind
> CONFIG += console
> CONFIG += c++11
> CONFIG -= app_bundle
>
> QMAKE_CXXFLAGS += -ftemplate-depth-5000 -fconstexpr-depth=5000
>
> QMAKE_LFLAGS += -Wl,--stack,4194304
>
> TEMPLATE = app
>
> SOURCES += main.cpp \
> Pattern.cpp
>
> HEADERS += \
> Peg.h \
> Pattern.h

this .pro files has some more options.
I did not write mine manually, it was autogenerated

>
> The point is to illustrate how one defines to qmake what .cpp and .h
> files are in a little project. So if you want to #include .cpp
> files then you should perhaps list those as HEADERS.

well actually I'm including just as headers.

Maybe I make mistakes writing the header itself.

>
> I did compare constexpr doing lot of things compile-time versus highly
> recursive code and so the QMAKE_CXXFLAGS and QMAKE_LFLAGS were altered
> for to allow unusual template, constexpr and stack depths, you likely
> don't need those settings. BTW I was convinced that constexpr works
> with Qt and is indeed a killer winner in runtime perfomance but causes
> horrible compile-times. ;)
>
> Better answers you will get in some Qt-related forums. Qt is compiling
> something that is not actually standard C++ and so is not strictly
> topical here.

well I'm not comfortable with forums out there :\
0 new messages