Program compiles and runs , but won't debug - missing includes
-
Program compiles and runs , but won't debug - missing includes
I am posting this in a new thread, it is not same as the other "includes" problem .
Here is anther "problem " with "#include " I could use some serious help with solving it. .
I am still not sure how to build my own application so I am STILL using cloned example. It works just fine and I like to sort of reverse engineer / debug it to learn more.
The example has simple "button" to perform bluetooth scan AND IT WORKS.
What I want is to see the source code processing this button push.
So I do in "device.ui"
right clicks on "scan" button and
Go to slot..
And this is the result
So the stupid question is
if the application compile and runs it must have all necessary "#includes" etc.so why am I getting this " cannot find it " error ?
what am I missing here ?
-
I believe I have identified "the problem".
The example application was build as Qt "text" application , what I am trying to do is debug it as "GUI". Hence the application does not know anything about "slots" and Qt Designer.So the question is
how to ADD GUI QT Designer (includes ) to my app?
(I will start with what is "Ui " object )I did try to the other way - start my app as Qt Designer , however, I do care more about NOT reinventing the real and working code , the GUI is pretty much just additional "bells and whistles" for me.
I think what got me confused was "device,ui" - hod did it get generated originally without using Qt Designer.
So if my theory is correct - is there a example using both Qt and Qt Designer SAME time ?That would help.
-
@AnneRanch said in Program compiles and runs , but won't debug - missing includes:
I think what got me confused was "device,ui" - hod did it get generated originally without using Qt Designer.
So if my theory is correct - is there a example using both Qt and Qt Designer SAME time ?QtDesigner does nothing itself... It's a helper program which translates a kind of WYSIWYG editor into XML style code. If you drag a Pushbutton on your form, the Designer saves all information (name, position, geometry...) about that button in your UI file...
Every project with UI files is a GUI project, where the programmer could have used the QtDesigner to create the GUI template or not.
A project without any GUI would be a console program.And.. yes, the example that you are currently using, IS a Qt GUI project. I would say 99% of all Qt examples are.
@Chris-Kawa made a very detailed explanation here.
Maybe some things become clearer if you read it again.
https://forum.qt.io/topic/107777/academic-question-how-to-manage-qt-many-colors/14@AnneRanch said in Program compiles and runs , but won't debug - missing includes:
how to ADD GUI QT Designer (includes ) to my app?
UI definitions can be added to the project by adding them to your pro file (be careful with the paths). It happens automatically, when you add a new one by using the context menu "wizard".
(Right click on your project folder, then "Add...")FORMS = \ device.ui \ service.ui
-
@AnneRanch said in Program compiles and runs , but won't debug - missing includes:
What I want is to see the source code processing this button push.
So I do in "device.ui"
right clicks on "scan" button and
Go to slot.."Go to slot" is a wizard for generating automatic name based connections. Don't use it for browsing as it can generate new code you didn't intended to. Examples don't usually use that feature. There could also be multiple connections to different slots so it most likely wouldn't take you where you want to go anyway.
The easiest way to find out how a particular widget from designer form is used is to select the widget, go to its properties panel, check its name (
scan
in this case) and do a search for its use from the generated ui pointer (ui->scan
in this case). You can usually tighten that to just connections withconnect(ui->scan
search. In this case it will lead you to a connection in the constructor ofdevice.cpp
and from there to a slotDeviceDiscoveryDialog::startScan()
.So the stupid question is
if the application compile and runs it must have all necessary "#includes" etc.
so why am I getting this " cannot find it " error ?This is because the example is not using the auto connection feature I mentioned. Also there are couple of ways you can include the generated content and this example is using a method (using the underscored Ui_ type) which is not recognized by the wizard (which expects namespaced class name).
IMO this auto connection thing is a misfeature and I suggest you avoid it.
-
@Chris-Kawa @Chris-Kawa made a very detailed explanation here.
Maybe some things become clearer if you read it again.
https://forum.qt.io/topic/107777/academic-question-how-to-manage-qt-many-colors/14I have to profusely apologize of being ignorant about this post. Real senior moment...
I did byte off more than I can chew and trying to "improve " bluetooth example by starting with my own "ui_mainwindow.hi" as a wrapper for other forms.
However, since "ui_...h" is generated I am not sure if I can "link / cascade " individual "ui .." headers.I did try using "tab" widget and it sort of works best for my project.
At this time I really need to pay attention to these headers, and make sure I do not mix C code "events" and "slots".
Thanks
-
@AnneRanch said in Program compiles and runs , but won't debug - missing includes:
with my own "ui_mainwindow.hi" as a wrapper for other forms.
However, since "ui_...h" is generated I am not sure if I can "link / cascade " individual "ui .." headers.You dont need to do that and you shouldn't.
ui_xxxxxx.h
files are generated byuic
from your ui definition file (xxxx.ui
)@Chris-Kawa said in Academic question - how to manage Qt "many colors"?:
qmake generates make rules that run uic on the mainwindow.ui file and generate ui_mainwindow.h file
Files mainwindow.h, mainwindow.cpp, moc_mainwindow.cpp and ui_mainwindow.h, all standard c++, are sent to compiler.
mainwindow.ui (the xml) is not compiled or used at runtime. Its only purpose is generating ui_mainwindow.h and it's a one-way thing.So you shouldnt try to include your own
ui_xxx.h
headers nor edit the existing ones (uic
will override changes anyway)@AnneRanch said in Program compiles and runs , but won't debug - missing includes:
starting with my own "ui_mainwindow.hi" as a wrapper for other forms
Start with
mainWindow.ui
, the corresponding header (ui_mainwindow.h
) which contains your GUI design definitions in c++ compilable language, will be generated byuic
@AnneRanch said in Program compiles and runs , but won't debug - missing includes:
I do not mix C code "events" and "slots"
Slots are basically just functions made for Qt's Signal & Slot mechanism (https://doc.qt.io/qt-5/signalsandslots.html)
Since Qt5 you can even connect your signals to normal functions by using the new synax (https://wiki.qt.io/New_Signal_Slot_Syntax)Events:
-
I am pressed for time so I did not read last post , I'll later.
Here is what I did not realize - the btscanner example I have been trying to copy is a part of "qtconnectivity examples bluetooth branch " . As such it contains many "includes" external to btscanner.
To continue with my philosophy not to reinvent the wheel and reuse perfectly working program I indeed need to start with "examples" and add or modify forms in existing btscanner - "sub - example ".
Not starting from scratch, the "includes" get to intertwined and "Adding exiting file ..." does not completely add everything.Back to some questions. if I may .
I did try to find the "slot" for "scan" but I do not get the mechanics.
Partially because I am still missing official names of QtDesigner panes.
I can select the "scan" button in "tree widgets" to get its properties but cannot figure out how to find the "scan -> pointer ".I realize that there already is "scan slot" but the only way to TRY to get there is to right click on "scan" and try to "Go to slot ..."
then I get this error
and I am stuck -
why is Ui::DeviceDiscovery "missing" ?
-
@AnneRanch
@Chris-Kawa answered to exact that question two posts earlier :)
https://forum.qt.io/topic/117850/program-compiles-and-runs-but-won-t-debug-missing-includes/4You should really start reading the replies first before asking the same or similar questions again and again.
I know, there is much to learn / to understand when you start with Qt or GUI programming in general.
-
@Pl45m4 Well it may look as I am asking same thing over and over .
But I feel like Archimedes "Give me the place to stand, and I shall move the earth."
There is ONLY one thing solid in Qt and its derivatives and even that is iffy. I may have asked this when I started years or so ago - give me some feel of concept.
Qt is a mix of C and C++ and as such there is one solid point - "main" function.
Than one can go UP the chain - to find "#include x.h" for "main".
Than the fun starts with main instance of QApplication app(argc, argv); class and other classes , where the "meat and potatoes" of the project reside . Eventually "app" gets executed.Now "the other classes" can be Qt , QtDesigenr etc.
With QtDesigenr we get x.h , x,ui , ui-x.h etc with well defined relations but "do your best guess" how it all fits together.The we have x.pro and that is mystery how it fits.
Not mentioning "make" "qmake" compiler...Enough rant.
If the examples projects were not created using "ui automation wizard" to build "slots" the Qt form designer is pretty useless to find them. .
(Yes I did read that part -see missing "Ui::xxx ")I did find the btscanner uses "connect" function and hopefully I can decipher how that works .
It looks as I can modify current class/ classes to include inheritance of "UI" class. Or create new class and inherit form "UI -less" original class and add "UI " . Just another layer of code.
Question
Does QtCreator has means to display "inheritance tree " stricture ?
Probably. -
@AnneRanch said in Program compiles and runs , but won't debug - missing includes:
Than the fun starts with main instance of QApplication app(argc, argv); class and other classes , where the "meat and potatoes" of the project reside . Eventually "app" gets executed.
Now "the other classes" can be Qt , QtDesigenr etc.
With QtDesigenr we get x.h , x,ui , ui-x.h etc with well defined relations but "do your best guess" how it all fits together.
The we have x.pro and that is mystery how it fits.It's neither random whether a Qt project runs or not, nor mysterious :)
@AnneRanch said in Program compiles and runs , but won't debug - missing includes:
Not mentioning "make" "qmake" compiler
qMake
/make
is not a compiler.@AnneRanch said in Program compiles and runs , but won't debug - missing includes:
I did find the btscanner uses "connect" function and hopefully I can decipher how that works .
The connect statement sets up what will happen, when the signal (button click, custom signal or whatever) is emitted.
Connections are a good place to start to see what's going on in a GUI project.
https://doc.qt.io/qt-5/signalsandslots.html@AnneRanch said in Program compiles and runs , but won't debug - missing includes:
It looks as I can modify current class/ classes to include inheritance of "UI" class. Or create new class and inherit form "UI -less" original class and add "UI " . Just another layer of code.
With
ui->.....
you get access to your widgets, you've (or somebody else) created in QtDesigner before. The corresponding file is theui_xxxxxx.h
header which is basically a c++ code "copy" or translation from yourxxxx.ui
file.@AnneRanch said in Program compiles and runs , but won't debug - missing includes:
Does QtCreator has means to display "inheritance tree " stricture ?
What do you mean by "display inheritance tree"?
You can see the inherited class in Qt docs or you can follow a class by debugging the Qt headers
Mark aQ....
class with your mouse and pressF1
to open help / docs in QtCreator or click on the class name while holdingShift
orCtrl
(I mix them up sometimes, but it's one of those two commands).
Might be helpful:
-
@AnneRanch said:
Does QtCreator has means to display "inheritance tree " stricture ?
Place cursor on a type and go to Tools -> C++ -> Open type hierarchy, or use a shortcut: Ctrl+Shift+T. It will open a type hierarchy pane.