So for some reason when I take out this from within the constructor of Mainwindow.cpp

try { // Create an instance. mongocxx::instance inst{}; // Connection string const auto uri = mongocxx::uri{uriString}; // Setup the connection and get a handle on the database. mongocxx::client conn{uri}; mongocxx::database db = conn["TestDB"]; // Grabbing the collection col = db["TestCol"]; test(); } catch(const std::exception& e) { // Handle errors. std::cout<< "Exception: " << e.what() << std::endl; }

then move it to the MainWindow.h header file, like this

private: std::string uriString = "<uriConnectionString>"; const mongocxx::uri uri = mongocxx::uri{uriString}; mongocxx::instance inst{}; mongocxx::client conn{uri}; mongocxx::database db = conn["TestDB"]; mongocxx::collection col = db["TestCol"];

it works...not sure why, so if someone who has more experience than myself has any input, please let me know I would love to see an explanation or thought process behind it. Otherwise this is what worked for me, hope it can help someone if they are stuck as well.