3

I'm trying to make a program that makes 6 numbers come out randomly.

This is my .pro file

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Lotto
TEMPLATE = app

CONFIG += c++11

SOURCES += main.cpp\
        mainwindow.cpp \
    lottogenerator.cpp

HEADERS  += mainwindow.h \
    lottogenerator.h

FORMS    += mainwindow.ui

This is my .h file

#ifndef LOTTOGENERATOR_H
#define LOTTOGENERATOR_H


#include <string>
#include <random>
#include <array>
#include <chrono>

class LottoGenerator
{
public:
    typedef std::chrono::high_resolution_clock myclock;

    LottoGenerator();

    std::array<int, 6> get();

private:
    int rand();

    std::mt19937 *engine;
    std::uniform_int_distribution<int> distribution;

    myclock::time_point beginning = myclock::now();
};

#endif // LOTTOGENERATOR_H

This is my .cpp file.

#include "lottogenerator.h"

LottoGenerator::LottoGenerator()
    : distribution(1,45)
{
    myclock::duration d = myclock::now() - beginning;
    unsigned int seed = d.count();

    engine.seed(seed);
}

std::array<int, 6> LottoGenerator::get()
{
    std::array<int, 6> numbers;

    numbers[0] = rand();
    numbers[1] = rand();
    numbers[2] = rand();
    numbers[3] = rand();
    numbers[4] = rand();
    numbers[5] = rand();

    return numbers;
}

int LottoGenerator::rand()
{
    return distribution(engine);
}

and when I run, "C1083: cannot open include file: 'chrono': no such file or directory" pops out.

It would be grateful if you could help:)

Simon Warta
  • 10,850
  • 5
  • 40
  • 78
apolokr2000
  • 31
  • 1
  • 2
  • Which is the compiler you are using? May be does not support C++11 fully... – marom Aug 03 '15 at 14:42
  • 1
    I do not use this compiler, but I think you also have to set `QMAKE_CXXFLAGS += -std=c++11`. This is discussed [here](https://stackoverflow.com/questions/16948382/how-to-enable-c11-in-qt-creator) – Cory Kramer Aug 03 '15 at 14:43
  • @CoryKramer Given that the asker uses MSVC, the flag you're referring to is not supported and unnecessary. MSVC supports whatever it supports, there's no way to coax it into supporting more. – Kuba hasn't forgotten Monica Aug 03 '15 at 15:00
  • Which version of MSVC are you using? – Simon Warta Aug 03 '15 at 17:32
  • I'm currently using MSVC 2010. Maybe I'm using too old version like Kuba Ober at below said. I'll install more current version of MSVC and try again. Thanks for the comments guys :) – apolokr2000 Aug 04 '15 at 11:37
  • 1
    I've installed MSVC 2015 community, but still getting same problem. Should I erase MSVC 2010 or is there some setting changes to make at QT creator? – apolokr2000 Aug 04 '15 at 14:51

1 Answers1

1

You are using a MSVC version that is too old. The error originates in the compiler, not in Qt Creator.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • I'm currently using MSVC 2010. I'll install more current version of MSVC and try again. Thanks for the comment :) – apolokr2000 Aug 04 '15 at 11:37
  • 1
    I've installed MSVC 2015 community, but still getting same problem. Should I erase MSVC 2010 or is there some setting changes to make at QT creator? – apolokr2000 Aug 04 '15 at 14:47
  • @apolokr2000 Of course you need to set up your Qt version and kit to use the right compiler, and you need to compile Qt with MSVC 2015 (!!). – Kuba hasn't forgotten Monica Aug 04 '15 at 17:00
  • Could you tell me how to set up Qt version and kit to use MSVC2015 and compile Qt with MSVC 2015? I have been searching google but can't find the way or maybe I'm not able to understand it T.T. Maybe because I just got into programming. It would be a great help if you could tell me how to set up Qt and compile Qt with MSVC 2015. Can't find anywhere in google. – apolokr2000 Aug 05 '15 at 16:53
  • @apolokr2000 1. Download and unzip Qt sources. 2. Open up the MSVC command prompt. 3. Make a build folder for Qt (*not* inside of the source folder!). 4. cd into the build folder. 5. `\configure -opensource -debug-and-release -ltcg -nomake examples -angle -platform win32-msvc2015` 6. `nmake && nmake install` 7. Now you have a built Qt. It will go faster if you download Qt Creator and give `-make-tool jom` to configure; first make sure that `jom.exe`'s folder is added to your path. jom comes with Creator. Note: Qt's documentation has all that! – Kuba hasn't forgotten Monica Aug 05 '15 at 17:44
  • Could you tell me how to make a build folder for Qt? After cd into the build folder, is it right to just copy&paste 5. and 6. into the command prompt? Lastly, could you tell me how I can give -make-tool jom to configure? I'm an utter beginner at programming and dealing with programs so questions just pop out. It would be very thankful if you could help me with those questions :) – apolokr2000 Aug 06 '15 at 08:43
  • @apolokr2000 You can create the build folder using any method you know of that creates empty folders. You can copy-paste #5 as long as you prepend it with proper source path for Qt. You give `-make-tool jom` to configure exactly as stated. It's another pair of arguments you pass to it on the command line. – Kuba hasn't forgotten Monica Aug 06 '15 at 13:25
  • Thanks for your continuous respsonse. So, I've created build folder named 'visual studio qt' and it's path is C:\visual studio qt. My source folder for qt creator is c:\qt. The source folder for qt creator has folders like 5.4, 5.5, docs, examples, vcredist etc.. I 'cd'ed into c:\visual studio qt at VS 2015 MSBuild command prompt and I copy&pasted \configure -opensource -debug-and-release -ltcg -nomake examples -angle -platform win32-msvc2015. Then the message saying 'acces denied' comes up. Can you tell me what I did wrong? – apolokr2000 Aug 07 '15 at 08:18
  • @apolokr2000 The angle brackets `<` and `>` were just to indicate which part you need to replace. You weren't meant to keep them. Finally, you want sources for Qt, not Qt Creator. Qt Creator is a nice IDE, but it has nothing to do with what you're trying to do. Qt is a toolkit. Qt Creator is an IDE. – Kuba hasn't forgotten Monica Aug 07 '15 at 15:05
  • Thanks a lot for your kind response. Somehow dll files in my computer are missing. I think maybe it was too hard to solve at my current level of knowledge about computer. Just have to skip this part and work on other things first and then come back. Anyway, it was really great to receive comments from you. Thanks Kuba Ober~^^ – apolokr2000 Aug 12 '15 at 14:34