Tuesday 29 April 2014

Visualizing the contents of QExplicitlySharedDataPointer or QSharedDataPointer in Visual Studio 2012 for Qt5

The path "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Packages\Debugger\Visualizers" contains qt5.natvis, which performs the role that autoexp.dat once did in previous versions of Visual Studio.

The following lines stomp on your QSharedData-derived classes and prevent showing their own data in the debugger:

    <Type Name="QSharedData">
        <Expand>
            <Item Name="[referenced]">ref._q_value</Item>
        </Expand>
    </Type>

So delete them and you'll be able to see what a QExplicitlySharedDataPointer<> actually points to!

Friday 25 April 2014

WINVER values

Version WINVER
Windows 8.1 _WIN32_WINNT_WINBLUE (0x0602)
Windows 8 _WIN32_WINNT_WIN8 (0x0602)
Windows 7 _WIN32_WINNT_WIN7 (0x0601)
Windows Server 2008 _WIN32_WINNT_WS08 (0x0600)
Windows Vista _WIN32_WINNT_VISTA (0x0600)
Windows Server 2003 with SP1, Windows XP with SP2 _WIN32_WINNT_WS03 (0x0502)
Windows Server 2003, Windows XP _WIN32_WINNT_WINXP (0x0501)

Tuesday 22 April 2014

How to make Qt's QApplication startup incredibly slow

If you want this code:

QApplication a(argc, argv);

...to take minutes instead of seconds, just at the Qt binary path to your library search paths:

QCoreApplication::addLibraryPath( qtpath + "/bin" );

I've no idea why!

Saturday 19 April 2014

Recursive C++ include processor for GLSL and other C-style languages

The important part here is how and where we insert #line directives. C-style preprocessors interpret this as telling them where to look, and in what source file, if there's an error or warning to be reported, e.g.

#line 12 "C:/code/media/shaders/myshader.glsl"

We put one of these at the top of each included file, plus the main file. And we put one after each included file is inlined to tell the preprocessor we're back in the parent. Thus instead of the useless GL shader compiler message:
0(4) : warning C7555: 'varying' is deprecated, use 'in/out' instead

- we get a useful one like this:
../../media/shaders/myshader.glsl(4) : warning C7555: 'varying' is deprecated, use 'in/out' instead

And in Visual Studio, you can double-click on this line in the Output window, it will zoom straight to the offending line!

void ProcessIncludes(std::string &src,std::string &filenameUtf8)
{
	size_t pos=0;
	src=src.insert(0,base::stringFormat("#line 0 \"%s\"\r\n",filenameUtf8.c_str()));

	int next=(int)src.find('\n',pos+1);
	int line_number=0;
	while(next>=0)
	{
		std::string line=src.substr(pos+1,next-pos);
		int inc=line.find("#include");
		if(inc==0)
		{
			int start_of_line=(int)pos+1;
			pos+=9;
		int n=(int)src.find("\n",pos+1);
		int r=(int)src.find("\r",pos+1);
			int eol=n;
			if(r>=0&&r<n)
				eol=r;
			std::string include_file=line.substr(10,line.length()-13);
			src=src.insert(start_of_line,"//");
			// Go to after the newline at the end of the #include statement. Two for "//" and two for "\r\n"
			eol+=4;
			std::string includeFilenameUtf8	=GetFileLoader()->FindFileInPathStack(include_file.c_str(),shaderPathsUtf8);
			std::string newsrc=loadShaderSource(includeFilenameUtf8.c_str());
			ProcessIncludes(newsrc,includeFilenameUtf8);
			//First put the "restore" #line directive after the commented-out #include.
			src=src.insert(eol,base::stringFormat("\r\n#line %d \"%s\"\r\n",line_number,filenameUtf8.c_str()));
			// Now insert the contents of the #include file before the closing #line directive.
			src=src.insert(eol,newsrc);
			next+=newsrc.length();
			line_number--;
		}
		else
			line_number++;
		pos=next;
		next=(int)src.find('\n',pos+1);
	}
}

Up-to-date (2013) Flex and Bison for Win32

http://sourceforge.net/projects/winflexbison/

Friday 18 April 2014