If you're just using one variable per setting (which is a bad plan if you're going to have more than 2-3 settings, but fine for now) you don't need to do any initialization whatsoever. Just read and set the variables and don't worry about whether they exist or not;
nil evaluates to
false in Lua, so it doesn't matter if they exist or not.
Code:
frame:RegisterEvent("ADDON_LOADED")
frame:SetScript("OnEvent", function(self, event, arg1)
if event == "ADDON_LOADED" and arg1 == "MyAddonName" then
window:SetShown(not QWindowHide)
end)
Code:
checkbox:SetScript("OnClick", function(self)
QWindowHide = self:IsChecked()
window:SetShown(not QWindowHide)
end)