Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 VA cannot find references of Qt's emit
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ahkow
Senior Member

33 Posts

Posted - Aug 11 2014 :  08:47:25 AM  Show Profile  Reply with Quote
Qt's emit keyword is a define which normally evaluates to nothing. The following:

// foo.cpp
void foo::bar1() {
  emit visibleChanged();
}

actually becomes this when being compiled:

// foo.cpp
void foo::bar1() {
  visibleChanged();
}


Problem 1:
When I position cursor to "signals: void visibleChanged()" in the following code and use Find References, VA only shows bar2's emit visibleChanged(). It fails to show bar1's emit visibleChanged() which is in foo.cpp.

// foo.h
class foo:public QObject {
  Q_OBJECT

public:
  foo() {}
  ~foo() {}
  void bar1();
  void bar2() {
    emit visibleChanged();
  }
signals:
  void visibleChanged();
}


Problem 2:
When I position to bar1's emit visibleChanged() in foo.cpp and use Find References, VA fails to show the following:
1) signals: void visibleChanged() in foo.h
2) bar2's emit visibleChanged() in foo.h


It can be argued that since emit evaluates to nothing, we can just avoid using this keyword altogether. But emit is an extremely important syntatic sugar in Qt development :)

Edited by - ahkow on Aug 12 2014 08:44:22 AM

feline
Whole Tomato Software

United Kingdom
19004 Posts

Posted - Aug 11 2014 :  1:31:57 PM  Show Profile  Reply with Quote
Which IDE and version of VA are you using?

I have set up a simple test here, using VS2013, VA 2034 and Qt 5.3.1, and Find References is finding all of the expected references for me in both cases. I have created a new, default C++ console application, and then just added 2 Qt directories to the C++ include directory list so that my project will compile, and VA can find and understand the Qt headers.

So I am wondering why I am getting such different results to you. The IDE, version of VA and version of Qt are obvious places to start looking.

zen is the art of being at one with the two'ness
Go to Top of Page

ahkow
Senior Member

33 Posts

Posted - Aug 12 2014 :  08:45:01 AM  Show Profile  Reply with Quote
I am using VS2013, VA 10.8.2043.0, Qt 5.3.1.
I just created a new Qt console application and still have the same problems.

This is how I created the project:
1) File -> New -> Project
2) Select "Qt5 Projects" -> "Qt Console Application"
3) Qt Add-in automatically sets Project Properties -> C/C++ -> Additional Include Directories to the following
.;$(QTDIR)\\include;.\\GeneratedFiles\\$(ConfigurationName);$(QTDIR)\\include\\QtCore;%(AdditionalIncludeDirectories)


What 2 Qt directories did you add?
Does you Find References show "emit" from both foo.cpp and foo.h ?

Edited by - ahkow on Aug 12 2014 08:45:28 AM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19004 Posts

Posted - Aug 12 2014 :  2:17:56 PM  Show Profile  Reply with Quote
Rather obvious now you say it, you have the Qt plugin installed. I did not install that here, since most support queries do not involve Qt, so I am wondering if that is a key difference.

I added the two directories:

C:\\Qt\\Qt5.3.1\\5.3\\msvc2013_64\\include
C:\\Qt\\Qt5.3.1\\5.3\\msvc2013_64\\include\\QtCore

Would you be able to send me a copy of the project you are working on? If so I could then study it here, and see if I can figure out what the key difference is that is causing the different behaviour. If so please submit the zip of the project via the form:

http://www.wholetomato.com/support/contact.asp

including this thread ID or URL in the description, so we can match it up.

When I run Find References on the function call "emit visibleChanged();" in the cpp, inside "bar1()" VA is finding 4 references in 2 files, 2 references per file, which seems to be correct to me.

zen is the art of being at one with the two'ness
Go to Top of Page

ahkow
Senior Member

33 Posts

Posted - Aug 13 2014 :  08:44:00 AM  Show Profile  Reply with Quote
If you did not install Qt Add-in, then I guess you have implemented visibleChanged() yourself in foo.cpp, that's why you have 4 references in 2 files :)

visibleChanged() is a signal, and signals implementations are meant to be generated by Qt's moc compiler. Qt Add-in will automatically set foo.h to "Custom Build Tool" to run c:\\Qt\\Qt5.3.1\\5.3\\msvc2013\\bin\\moc.exe, and generate moc_foo.cpp. Implementation of visibleChanged() is generated in moc_foo.cpp.

I have uploaded the test project: http://goo.gl/KICQUd

Here's the result of Find References to visibleChanged() in foo.h, notice the code generated in moc_foo.cpp:


And here's the result of Find References to visibleChanged() in foo.cpp:



VA seems to treat visibleChanged() in foo.cpp and foo.h as different methods if I use 'emit'. If I remove all 'emit' from both files, all visibleChanged() in 3 files are correctly shown in Find References.






Edited by - ahkow on Aug 13 2014 09:19:22 AM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19004 Posts

Posted - Aug 13 2014 :  11:14:55 PM  Show Profile  Reply with Quote
I had completely forgotten about the moc files. I used to work with Qt quite a lot, but that was years ago, so you are right, my test project did not contain the moc file.

After finally working out how to download your test project I am seeing the same problem here. Nothing to do with you, but the download button was hidden until I moved my mouse to the top of the screen. What sort of system is that? I did not see any visual clues I was supposed to do that, and only discovered it by accident, sigh.

Can you please create a new text file called "va_stdafx.h" and place it in the same directory as your SLN or VCXPROJ file. Inside the file add the single line:

#define emit

and make sure the file ends with a blank line. Now press the button:

VA Options -> Performance -> Rebuild symbol databases

and restart VS2013. This file does not need to be added to the solution, VA searches for it and uses its content if it is found:

http://docs.wholetomato.com/default.asp?W302

This has fixed the problem for me, using your test project. So hopefully it will fix the problem for you as well.

zen is the art of being at one with the two'ness
Go to Top of Page

ahkow
Senior Member

33 Posts

Posted - Aug 14 2014 :  01:09:32 AM  Show Profile  Reply with Quote
That sort of system is called Google Drive :)

Thanks, va_stdafx.h did the trick!
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19004 Posts

Posted - Aug 14 2014 :  12:10:45 PM  Show Profile  Reply with Quote
I do use Google drive a bit, but I was not familiar with that screen. Normally Google products seem more usable up front, or I am just more used to them.

Thank you for the update, I am glad this worked for you Since all that matters for the "va_stdafx.h" file is its position, you can check this into source control along side the rest of your solution without effecting anything else, since the IDE does not know about this file.

zen is the art of being at one with the two'ness
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000