Solved Signal not emitted or not received
-
@mscottm said in Signal not emitted or not received:
I think I can pare down the code I've added to the example, but I don't think I could figure out what to cut from the example code, and maybe how I integrated it is part of the issue...? Would it be okay to just post the pared down part that I added to the example code?
Sure, go ahead.
-
Okay - I wasted another week and a half trying to solve this myself with no result :(
Not sure how to pass along my minimized code - is there a way to attach a zip? Even though it's shortened, it seems like a lot to paste here.
-
@MScottM
Hi
The upload here is not so cooperative with zip files.
So you have to use some upload service (google drive, pcloud or similar)
that can give an URL to paste here.
https://wetransfer.com/ can also do it with no install
if you swich to "send as link" mode.
using the the round [...] button. -
@MScottM said in Signal not emitted or not received:
Not sure how to pass along my minimized code - is there a way to attach a zip?
Like @mrjj said, upload your zip file to an external file host and post the link here.
Okay - I wasted another week and a half trying to solve this myself with no result :(
...
Even though it's shortened, it seems like a lot to paste here.Thank you for making the effort. Upload the zip file containing your whole project (so that I can just click "build" and run it -- it doesn't matter if I need a CAN bus device); I'm happy to look through your work.
-
Here is the link to a zip file:
Notes:
There is a text file needed (included in file) that goes into the build folder. Steps to test my non-working signal (in pMessageProcessor.cpp):CAN cable isn't needed - on running the program:
Select 'virtualcan' from drop down
Check 'Custom Configuration' and set 'Receive Own' to True - click OK
At menu on top click Monitor -> P Bus
In center box click 'Module 1'(Back to Can Example Window)
Check 'Extended Format' and in the 'Frame ID' box type FF0400
In the 'Payload' box type eight bytes, i.e. 11 22 33 44 55 66 77 88 and sendThank you for taking the time to take a look!
-
@MScottM OK, I've downloaded your code and am looking through it. I will probably post back in the next day or two.
In the meantime, I've got a few questions:
- You have two different instances of
pMessageProcessor
in your code (one is a member variable in MainWindow, the other is in your main.cpp). Which one did you intend to use? (Similarly, you have 2 different instances ofQQmlEngine
)- An important part of minimizing your code for troubleshooting is to get rid of unneeded objects.
- You mentioned that this is a "learning project". Could you describe what you're focussing on learning?
- Is it learning to use Qt's CAN classes? Learning to integrate C++ and QML? Learning how to create GUIs in QML? A combination of the above? Something else completely?
- You have two different instances of
-
Hi @JKSH
Again, thanks for taking the time to look through what I've done.
To answer your questions in reverse order:
-
The simple answer is 'all of the above'. A part of my job includes working with equipment that uses CAN bus to communicate, and I thought it would be interesting to learn some more about Qt while making a tool that could be useful for me when troubleshooting. Integrating QML GUIs with C++ seems like the best way to make interesting useful programs. While I've had one or two formal classes in programming (enough to make me dangerous), I'm in no way a computer science major, and I apologize for the amateur mistakes I must be making!
-
With respect to QQmlEngine, I was wondering, and asked in one of my posts above, whether it was an issue to create a second one, and if that might be part of my problem. Regarding pMessageProcessor, I added that to main.cpp in order to get the connect statement working, as I couldn't seem to get it to work anywhere else.
Edit: that's interesting...the forum is auto numbering my replies!
-
-
@MScottM You're most welcome! Always happy to help a willing learner.
With respect to QQmlEngine, I was wondering, and asked in one of my posts above, whether it was an issue to create a second one, and if that might be part of my problem.
Yes, that is definitely part of your problem. The diagram below summarizes your code:
(Red arrows show signal-slot connections; Blue lines show QML contexts)
You have created 2 separate message processors and 2 separate QML engines.
- Your first
pMessageProcessor
(in main.cpp) receives theMainWindow::canMessageOut()
signal. However, you have not connected anything to thispMessageProcessor
's signals. - Your second
pMessageProcessor
(in mainwindow.h) has its signals connected to the signal handlers ModulePage. However, it does not receiveMainWindow::canMessageOut()
so it never emits its signals.
From the diagram, can you see what needs to happen for your code to work as you want? Try to implement the change in your code. If you can't figure it out, describe what you want to do and I'll give you some pointers.
The simple answer is 'all of the above'. A part of my job includes working with equipment that uses CAN bus to communicate, and I thought it would be interesting to learn some more about Qt while making a tool that could be useful for me when troubleshooting.
When learning multiple new concepts, I recommend the "divide and conquer" approach. Focus on one thing at a time -- you will be able to learn much faster this way. Mixing multiple concepts into the same study makes it much harder to troubleshoot things.
While I've had one or two formal classes in programming (enough to make me dangerous), I'm in no way a computer science major, and I apologize for the amateur mistakes I must be making!
You don't need a computer science major to learn Qt, but you do need to be systematic and patient.
Integrating QML GUIs with C++ seems like the best way to make interesting useful programs.
You can absolutely make interesting useful programs using Qt Widgets too.
Since the CAN example already has a solid GUI based on Qt Widgets, I highly recommend you first learn by adding new functionality to that example by implementing new widgets. Leave QML out of it for now.
Add QML after you have mastered widgets, or implement QML in a separate, smaller, and simpler project which doesn't have such a complex web of connections.
- Your first
-
Hi @JKSH ,
THANK YOU!! Your diagram made what was happening very clear. I'll try to use something like that in the future when plotting connections.
I made the following changes, and now it works as I expected it to:
I deleted the contextProperty statements and moved the class declaration and connect statement out of main.cpp and placed them in MainWindow.cpp, as well as creating the QQmlApplicationEngines and setting the engine context properties in the same place - eliminating 'engine1', and that was basically all it took!
When learning multiple new concepts, I recommend the "divide and conquer" approach. Focus on one thing at a time -- you will be able to learn much faster this way. Mixing multiple concepts into the same study makes it much harder to troubleshoot things.
I appreciate this advice, and this is actually what I try do. When I tackle a new concept, I'll create a small application that does only the thing I'm trying to learn, but then I'll try to fit that functionality into a larger application that has more going on. This is actually sort of a culmination of trying different concepts, but I obviously bit off more that I could chew. This is the first time I've tried taking code that was complete and working (the CAN example) and adding my own functionality. I have made other small applications that combine QML and C++.
Since the CAN example already has a solid GUI based on Qt Widgets, I highly recommend you first learn by adding new functionality to that example by implementing new widgets. Leave QML out of it for now.
Add QML after you have mastered widgets, or implement QML in a separate, smaller, and simpler project which doesn't have such a complex web of connections.
I find QML very easy to work with and Qt Widgets, not so much, (although I have created small GUI's strictly with Qt Widgets before). This tells me you're probably right about learning more about the Widgets framework.
-
@MScottM said in Signal not emitted or not received:
I made the following changes, and now it works as I expected it to:
Congrats! Happy coding.
Your diagram made what was happening very clear. I'll try to use something like that in the future when plotting connections.
A pen and paper are very powerful programming tools.
I appreciate this advice, and this is actually what I try do. When I tackle a new concept, I'll create a small application that does only the thing I'm trying to learn, but then I'll try to fit that functionality into a larger application that has more going on.... I have made other small applications that combine QML and C++.
OK, it sounds like you have a good systematic workflow.
I find QML very easy to work with and Qt Widgets, not so much, (although I have created small GUI's strictly with Qt Widgets before). This tells me you're probably right about learning more about the Widgets framework.
The ranking from easiest-to-hardest is roughly:
- Pure QML
- Pure C++
- Mixing QML and C++
#3 depends on your ability to do #1 and #2, so you'll most likely benefit from strengthening your understanding of C++.