Loading and Displaying a DXF file

I’m just playing with QCad source code because I’m a Qt programmer and I found this code really interesting and strong.
I want to load and display a .dxf file in a GraphicsViewQt . I used this code but I got a black screen :

	RMemoryStorage* storage = new RMemoryStorage();
	RSpatialIndexNavel* spatialIndex = new RSpatialIndexNavel();
	RDocument * document = new RDocument(*storage, *spatialIndex);
	RGraphicsViewQt *view = new RGraphicsViewQt;
	
	RDocumentInterface * documentInterface = new RDocumentInterface(*document);
	documentInterface->importFile("2.dxf", "DXF 2000");

	RGraphicsSceneQt *scene = new RGraphicsSceneQt(*documentInterface);
	view->setScene(scene);
	view->show();

What’s wrong with my code ?

The code looks fine and is almost complete.

First, please make sure that the DXF file can be found and there are no other errors. The return value of importFile should be 0, if the import was successful.

After the import, the scenes and views have to be regenerated with:
documentInterface.regenerateScenes();Performing an auto zoom is usually also a good idea:
documentInterface.autoZoom();May I ask, why you are experimenting with QCAD code in C++, not ECMAScript (JavaScript)? I’d highly recommend to use ECMAScript to extend QCAD or to build new applications based on QCAD technology.

This simple example could look like this in ECMAScript (as standalone application):

File ‘dummy.js’:
var storage = new RMemoryStorage();
var spatialIndex = new RSpatialIndexNavel();
var document = new RDocument(storage, spatialIndex);
var view = new RGraphicsViewQt();

var documentInterface = new RDocumentInterface(document);

var scene = new RGraphicsSceneQt(documentInterface);
view.setScene(scene);
view.show();

documentInterface.importFile(“/path/to/file/dummy.dxf”, “DXF 2000”);
documentInterface.regenerateScenes();
documentInterface.autoZoom();

QCoreApplication.exec();It can be run like this:
./qcad -autostart dummy.jsScripts can access the entire API of QCAD and almost all of Qt. Using C++, you would likely sooner or later get to a point where you would have to re-implement some of the QCAD code written in ECMAScript (most of the user interface related code, all of the tools and most widgets are implemented in ECMAScript).

Really thank you.
The error code is ‡IoErrorNoImporterFound. How to register a DXF importer?
Honestly I just wanted the DXF importing and displaying of this project. So I tried to just use cpp files related to this purpose . I tried to add them to a new project and compiled them.
But now I eagerly want to find out how this project is organized. Although I’m Qt expert but I don’t know any thing about scripting and its power. Does this nice project have any developer documentation? Is it possible to be one of its developers? I think this project is really great. Its structure, its design and its framework.

If you’re creating a standalone application in C++ that does not require QCAD, you will have to load the plugins explicitly, for example in your main:
RPluginLoader::loadPlugins(true);This will load all plugins available in ./plugins. You can for example copy the plugins included with QCAD into your local ./plugins directory for DXF and DWG support.

All official documentation is linked from this site:

API and other developer documentation can be found at:

Yes, of course!
QCAD is available under GPLv3 with exceptions which allow proprietary plugins and add-ons.
If you agree to these terms, you can contribute to QCAD in various ways such as C++ development, ECMAScript development, bug fixing, translations, etc. Here’s a brief overview over the areas in which contributions are possible:

Welcome aboard :slight_smile: Don’t hesitate to post to the forum if you have any questions.

You’re AWESOME :smiley:
I’m really happy to be here. I’ve lots of questions. :smiley: I ask them in a new topic in order to respect to the forum rules ! :sunglasses: