How to create new Tilesets

I have build only the libtiled library from the source files, and used it to import it into a C++ app.
I am currently just playing around with it, but when I try to create a tileset;

auto tileset = Tiled::Tileset::create(“DummyTileset”, 32, 32, 0, 0);

It keeps giving me the error:

QPixmap: Must construct a QGuiApplication before a QPixmap

At the start of my main() function, I did create an QGuiApplication though.

QGuiApplication app(argc, argv);

Even if my application is only:

int main(int argc, char* argv[])
{
    QGuiApplication app(argc, argv);
    auto tileset = Tiled::Tileset::create("DummyTileset", 32, 32, 0, 0);
    std::cout << "It worked\n";
    return 0;
}

I have looked through the source code, but since I have a novice understanding of C++, I can’t find the issue.
I hope someone can help me to the right trail, thank you.

Hmm, that’s odd. Using Tiled 1.11.2 I can’t reproduce this on Fedora (I’ve installed tiled-devel):

bjorn@thor:libtiled_example$ cat libtiled_example.pro 
TEMPLATE = app
TARGET = libtiled_example
LIBS += -ltiled
SOURCES += main.cpp
bjorn@thor:libtiled_example$ cat main.cpp
#include <QGuiApplication>
#include "tiled/tileset.h"
#include <iostream>

int main(int argc, char* argv[])
{
    QGuiApplication app(argc, argv);
    auto tileset = Tiled::Tileset::create("DummyTileset", 32, 32, 0, 0);
    std::cout << "It worked\n";
    return 0;
}
bjorn@thor:libtiled_example$ ./libtiled_example 
It worked

Can you provide more information that’d allow me to reproduce this issue?

I am using debug mode, in Visual Studio 2022. I did make sure to build the library .qbs with those that version in mind. The code is also made in VS, maybe that can make a difference?

To add to that, I installed Qt with MSVC2022 aswell (Windows 11). I only build the .qbs file from the libtiled folder (from the github ./src). The rest of the github(‘s source files) I did not build.

I think the problem lied by the way I built the Tiled library. An other member of my project group built it with CMake instead of the .qbs and that one does work.

1 Like